开发者

Process.Start Help in Java

开发者 https://www.devze.com 2023-01-30 05:00 出处:网络
Is it possible to do the following C#开发者_运维问答 Code in Java? Process.Start(\"c:/test.exe\", \"filearg1,filearg2,filearg3\");

Is it possible to do the following C#开发者_运维问答 Code in Java?

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");


I recommend that you read "When Runtime.exec() won't" article.


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.

0

精彩评论

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