代码: 全选
//command
private static final String command="ps aux | grep 'java -jar' | grep -v grep";
Process p = Runtime.getRuntime().exec(command);
正确的办法:
linux下:
代码: 全选
String[] commands = { "/bin/sh", "-c", command };
Process ps = Runtime.getRuntime().exec(commands);
windows下:
代码: 全选
String[] commands = { "cmd", "/c", command};
Process ps = Runtime.getRuntime().exec(commands);