import subprocess
import os
prefix = os.path.expanduser("~/.bin/kb/")
p = subprocess.Popen([(prefix + "koreball"),(prefix + "/data"),'3'])
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Your can try with the Runtime.exec
method.
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("myprocess");
The method returns a Process
that can be used to:
- Retrieve the process output, input and error streams
- Retrieve the process output code
- Kill the process
- Wait for the end of the process execution
回答2:
It's not clear what you're asking, but if you're looking for the Java equivalent of Popen()
, you want Runtime.exec()
.
回答3:
Use ProcessBuilder e.g.
static void SimpleProcess() throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder("ls", ".")
.inheritIO();
Process p = pb.start();
int retval = p.waitFor();
System.out.println("exited with code " + retval);
}