简体   繁体   中英

Process.Start Help in Java

是否可以在Java中执行以下C#代码?

Process.Start("c:/test.exe", "filearg1,filearg2,filearg3");

Yes, but you need to use Runtime and Process classes.

You can use something like this:

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("c:/test.exe filearg1,filearg2,filearg3");

我建议您阅读“当Runtime.exec()不会”文章。

ProcessBuilder is the recommended way of managing external processes since Java 5. There is a nicer interface for manipulating environment variables, and an option to automatically redirect standard error to standard output.

Unfortunately, as with Runtime.exec() you still have to manually start up a thread to consume processes output stream (and error stream) to prevent it from blocking the system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM