Getting process ID with java apache default executor -
i'm writing code runs commandline using default executor of apache. found way exit code couldn't found way process id.
my code is:
protected void runcommandline(outputstream stdoutstream, outputstream stderrstream, commandline commandline) throws innerexception{ defaultexecutor executor = new defaultexecutor(); pumpstreamhandler streamhandler = new pumpstreamhandler(stdoutstream, stderrstream); executor.setstreamhandler(streamhandler); map<string, string> environment = createenvironmentmap(); try { returnvalue = executor.execute(commandline, environment); } catch (executeexception e) { // , on... } returnvalue = e.getexitvalue(); throw new innerexception("execution problem: "+e.getmessage(),e); } catch (ioexception ioe) { throw new innerexception("io exception while running command line:" + ioe.getmessage(),ioe); } }
what should in order processid?
there no way retrieve pid of process using apache-commons api (nor using underlying java api).
the "simplest" thing have external program executed in such way program returns pid somehow in output generates. way can capture in java app.
it's shame java doesn't export pid. has been feature-request over decade.
Comments
Post a Comment