在Java中使用参数运行可执行命令? [英] Running an executable command in Java with parameters?

查看:124
本文介绍了在Java中使用参数运行可执行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我很了解如何在Java中使用Runtime命令来使可执行文件运行.我的问题是我该如何编码以合并一个参数,例如在目标的快捷方式属性中看到的参数,即目标:"C:...... \ notepad.exe" -w.我可以通过什么方式将-w这样的参数合并到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.

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

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

这篇关于在Java中使用参数运行可执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆