在Windows操作系统下。
我通过Runtime.getRuntime().exec()启动子进程;我想向进程发送一个"ctrl-c“来停止它。
我用Runtime.getRuntime().exec("ping google.com -n 100000“)做了一个小例子;代码可以在那里找到:http://pastebin.com/f6315063f
到目前为止,我尝试通过进程outputStream发送字符'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信号。我该怎么做呢?
发布于 2016-01-15 11:34:52
要终止,您可以使用以下代码taskkill java:
Runtime.getRuntime().exec("taskkill /f /im java.exe");希望这对你有所帮助!
https://stackoverflow.com/questions/1835885
复制相似问题