在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();
Run Code Online (Sandbox Code Playgroud)
我不想杀死进程,我只想发送一个Ctrl-C信号.我怎样才能做到这一点?