且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Java中使用参数运行可执行命令?

更新时间:2023-11-11 20:19:52

使用

Use a ProcessBuilder and supply the necessary arguments to its constructor:

ProcessBuilder builder = new ProcessBuilder("C:\\path\\to\\notepad.exe", "-w");

第一个参数始终是应用程序,其他任何参数(如果存在)将是要添加到应用程序的参数.

The first argument is always the application, any other arguments (if present) will be the arguments to add to the application.

然后您可以调用start()方法来启动它,并根据需要获取过程对象.

You can then call the start() method to start it and grab the process object back if you so wish.