[code="java"]public static void executeCommand(String command) {
System.out.println(command);
Runtime r = Runtime.getRuntime();
Process p = null;
try {
p = r.exec(command);
} catch (IOException e) {
e.printStackTrace();
}
}[/code]
传 notepad , calc 都能打开,但是启动winword报错。
本人在win+r打开中可以用winword命令,打开word。但是在cmd中,无法找个命令。
求方法解决,我知道可以直接通过C:\******\winword.exe绝对路径可以打开,但是安装在其他盘这个就无效。
谢谢。
(本意是做一个swing的快速小工具集,然后还能做些简单的自定义。)
[code="java"]
winword.exe
java.io.IOException: Cannot run program "winword.exe": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:431)
at java.lang.Runtime.exec(Runtime.java:328)
at demoSysTool.SysUtils.main(SysUtils.java:109)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 4 more
[/code]