【发布时间】:2017-06-15 01:51:55
【问题描述】:
我正在尝试获取我使用流程构建器启动的流程的输出,但是输出看起来像是来自 applescript 的东西,而不是流程的实际输出:
代码:
public static void main(String[] args) {
System.out.println(getJavaOutput());
}
public static String getJavaOutput() {
try {
//kill -9 $(ps -p $PPID -o ppid=)
String output = "";
ProcessBuilder macBuilder = new ProcessBuilder("osascript", "-e",
"tell application \"Terminal\" to do script \"jps -lV && exit\"");
Process p2 = macBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p2.getInputStream()));
String line;
while((line = reader.readLine()) != null){
output += line + System.getProperty("line.separator");
}
return output;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
预期输出:
2680 sun.tools.jps.Jps
1289
实际输出:
tab 1 of window id 742
【问题讨论】:
标签: java macos process terminal