processbuilder

How to get PID of process I've just started within java program?

匆匆过客 提交于 2019-11-26 00:55:09
问题 I\'ve started a process with following code ProcessBuilder pb = new ProcessBuilder(\"cmd\", \"/c\", \"path\"); try { Process p = pb.start(); } catch (IOException ex) {} Now I need to know the process\'s pid that I\'ve just started. 回答1: There is no public API for this yet. see Sun Bug 4244896, Sun Bug 4250622 As a workaround: Runtime.exec(...) returns an Object of type java.lang.Process The Process class is abstract, and what you get back is some subclass of Process which is designed for your

Difference between ProcessBuilder and Runtime.exec()

孤街浪徒 提交于 2019-11-26 00:28:08
问题 I\'m trying to execute an external command from java code, but there\'s a difference I\'ve noticed between Runtime.getRuntime().exec(...) and new ProcessBuilder(...).start() . When using Runtime : Process p = Runtime.getRuntime().exec(installation_path + uninstall_path + uninstall_command + uninstall_arguments); p.waitFor(); the exitValue is 0 and the command is terminated ok. However, with ProcessBuilder : Process p = (new ProcessBuilder(installation_path + uninstall_path + uninstall_command

How to get PID of process I've just started within java program?

一个人想着一个人 提交于 2019-11-25 19:30:31
I've started a process with following code ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "path"); try { Process p = pb.start(); } catch (IOException ex) {} Now I need to know the process's pid that I've just started. This page has the HOWTO: http://www.golesny.de/p/code/javagetpid On Windows: Runtime.exec(..) Returns an instance of "java.lang.Win32Process") OR "java.lang.ProcessImpl" Both have a private field "handle". This is an OS handle for the process. You will have to use this + Win32 API to query PID. That page has details on how to do that. Amir Afghani There is no public API for