ProcessBuilder 的问题 [英] trouble with ProcessBuilder
本文介绍了ProcessBuilder 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
// following code works fine n open notepad...
class demo
{
public static void main(String args[])
{
try{
ProcessBuilder pb=new ProcessBuilder("notepad");
pb.start();
}catch(Exception e)
{System.out.print(e);}
}
}
//however the above code throws an exception when any other system program is executed
class demo
{
public static void main(String args[])
{
try{
ProcessBuilder pb=new ProcessBuilder("calculator");
pb.start();
}catch(Exception e)
{System.out.print(e);}
}
}
上面的程序抛出以下异常:
the above program throws following exception:
java.io.IOException: Cannot run program "Calculator": CreateProcess error=2, The system cannot find the file specified
推荐答案
您应该包含可执行文件的完整路径(包括目录和 .exe 扩展名).
You should include the full path to the executable (including the directories and the .exe extension).
实际上应该可以从您收到的错误消息中看出:-)
Should actually be apparent from the error message you got :-)
("notepad"
工作的原因表明它将搜索 %PATH%
并在必要时尝试附加 .exe
.这导致我相信 "calc"
也可以工作:-)
(The reason "notepad"
worked indicates that it will search %PATH%
and try to append .exe
if necessary. This leads me to believe that "calc"
may also work :-)
这篇关于ProcessBuilder 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文