Process Object from Apache Commons Exec

2019-08-03 23:15发布

问题:

I'm using the Apache Commons Exec jars for creating processes. However I'd like to get control of the process id of processes being invoked.

Is there a way of getting the 'Process' object from the Apache Commons Exec api? I did'nt fine any public methods that returns the 'Process class.

回答1:

See http://commons.apache.org/exec/apidocs/index.html

Interface CommandLauncher contains several exec methods that return Process.

But anyway you do not have any way to control the process ID: it is the OS responsibility. Moreover standard java API does not allow you even to retrieve the process ID. There was a trick in older java versions: the implementation of Process contained int field pid that could be retrieved using reflection. But this was changed in version 1.6.