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.
精彩评论