[英]Executing cmd commands with Java
I am trying to run 2 cmd
commands in order to start tshark
from cmd
. 我正在尝试运行2个
cmd
命令,以便从cmd
启动tshark
。 Can you please help me understand why this code does not work? 您能帮我了解为什么此代码不起作用吗?
Process p = Runtime.getRuntime().exec("cmd.exe");
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
writer.write("cd C:/Program Files/Wireshark");
writer.flush();
writer.write("tshark.exe -i 1 -p -a duration:60 -w C:/Users/User/Desktop/AutomatedProtocolsPcapsCreator/CreatedPcaps/fileName.pcap");
writer.flush();
Use ProcessBuilder
. 使用
ProcessBuilder
。 There are some gotchas around capturing console output, but otherwise I was very happy with this API. 捕获控制台输出有一些陷阱,但是除此之外,我对此API感到非常满意。
new ProcessBuilder("tshark.exe", "-i", "1", "-p", "-a", "duration:60", "-w",
"C:/Users/User/Desktop/AutomatedProtocolsPcapsCreator/CreatedPcaps/fileName.pcap")
.start()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.