0
我試圖得到一個過程中,我推出使用進程生成但是輸出似乎看起來像是從AppleScript的東西,而不是過程的實際輸出的輸出:過程的InputStream沒有返回過程輸入(OSX)
代碼:
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