开发者

What is the Java equivalent of Python's subprocess.Popen()?

开发者 https://www.devze.com 2023-01-16 18:43 出处:网络
import subprocess import os prefix =开发者_开发技巧 os.path.expanduser(\"~/.bin/kb/\") p = subprocess.Popen([(prefix + \"koreball\"),(prefix + \"/data\"),\'3\'])
import subprocess
import os

prefix =开发者_开发技巧 os.path.expanduser("~/.bin/kb/")
p = subprocess.Popen([(prefix + "koreball"),(prefix + "/data"),'3'])


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


It's not clear what you're asking, but if you're looking for the Java equivalent of Popen(), you want Runtime.exec().


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消