作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在Java中,我尝试运行:Process p = Runtime.getRuntime().exec("C:\\Windows\\System32\\chgport.exe");
以及进程 p = Runtime.getRuntime().exec("chgport.exe");
但出现以下异常:
java.io.IOException: Cannot run program "C:\Windows\System32\chgport.exe": CreateProcess error=2, The system cannot find the file specified
我正在使用 NetBeans IDE,它使用管理员凭据运行。
最佳答案
我尝试了你的代码,它工作正常,请像这样尝试:
String[] command = {"chgport"};
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(new File("C:/Windows/System32/"));
pb.redirectErrorStream(true);
Process p = pb.start();
我尝试了 Eclipse 中的两种方法,并且都工作正常您是否有可能没有以管理员权限运行 IDE?
您可以尝试关闭IDE并右键单击以管理员身份运行吗?
try {
Process p = Runtime.getRuntime().exec("C:\\Windows\\System32\\mspaint.exe");
p.waitFor();
String[] command = {"mspaint"};
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(new File("C:/Windows/System32/"));
pb.redirectErrorStream(true);
Process p2 = pb.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
关于java - 为什么Java中Runtime.getRuntime().exec()找不到 "chgport.exe"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52996822/
在Java中,我尝试运行: Process p = Runtime.getRuntime().exec("C:\\Windows\\System32\\chgport.exe"); 以及 进程 p =
我是一名优秀的程序员,十分优秀!