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

So i understand how to use the Runtime command in java pretty well to get an executable to run. My question is how would i code that to incorporate a parameter such as you would see in the target in a shortcut property, i.e. target: "C:......\notepad.exe" -w. In what way could I incorporate a parameter such as -w into the Java runtime command.

解决方案

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.

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值