在Windows操作系统下。
我通过Runtime.getRuntime()。exec()启动一个子进程;我想向进程发送“ ctrl -c”以停止它。
我用Runtime.getRuntime()。exec(“ ping google.com -n 100000”);做了一个小例子。可以在以下位置找到代码:http : //pastebin.com/f6315063f
到目前为止,我尝试通过Process outputStream发送char'3'(Ctrl-C字符)。
这是一些代码:
cmd = re.exec("ping google.com -n 10000");
out = new BufferedWriter (new OutputStreamWriter(cmd.getOutputStream()));
input = new BufferedReader (new InputStreamReader(cmd.getInputStream()));
char ctrlBreak = (char)3;
//Different testing way to send the ctrlBreak;
out.write(ctrlBreak);
out.flush();
out.write(ctrlBreak+"\n");
out.flush();
我不想终止该进程,我只想发送Ctrl-C信号。我怎样才能做到这一点?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句