Java:执行/cmd/c start path-with-spaces\program.exe [英] Java: Execute /cmd /c start path-with-spaces\program.exe

查看:50
本文介绍了Java:执行/cmd/c start path-with-spaces\program.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多关于这个问题的内容,但我找到的答案并不完全有效.

I've read a lot about the question but the answers I have found don't work completely.

我尝试运行此代码:

String[] args = {"cmd","/c","start","C:\\Program Files\\XML Marker\\xmlmarker.exe"};
Runtime rt = Runtime.getRuntime();
ProcessBuilder pb = new ProcessBuilder(args);
Process pr = pb.start();      
//Process pr = rt.exec(args);

因为我的路径中有空格,所以我使用 String 数组将参数传递给 Process但是……它打开了一个 DOS 命令窗口,但没有启动我的程序,就好像忽略了参数

As I have spaces in my path, I use String array to pass the arguments to the Process But ... it opens a DOS command window but doesn't launch my program, as if the parameters where ignored

我尝试了 rt.exec(args) 和 pb.start() ...相同的结果

I tried with rt.exec(args) and pb.start() ... same result

有人能给我一些建议吗?谢谢.

Could someone give me some advice please ? Thank you.

推荐答案

无需同时拥有start"和cmd".您可以放心地取出开始".如果在start"命令中使用括在引号中的参数,它会将其视为新命令窗口的标题.

No need to have a "start" and "cmd" at the same time. You can safely take out "start". If you use a parameter enclosed in quotes with the "start" command, it treats it as a Title for a new command window.

这篇关于Java:执行/cmd/c start path-with-spaces\program.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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