我试图在Java中运行一个外部进程,但我不知道为什么我的代码不能工作。它适用于任何其他'cmd‘命令(例如/c目录)。如果我用cmd /c dir替换cmd sc sdshow w32time,它就能工作。
下面是我的代码:
public class services2 {
public static void main(String args[]) {
try {
Process p = Runtime.getRuntime().exec("cmd sc sdshow w32time");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
}
} catch (IOException e1) {
} catch (InterruptedException e2) {
}
System.out.println("Done");
}
}有什么想法吗?
发布于 2013-04-11 12:01:40
你的问题似乎是sc不是cmd的一个论据。
您需要的是:
sc sdshow w32time
https://stackoverflow.com/questions/15940384
复制相似问题