I have the following code:
Process proc;
try
{
ProcessBuilder procBuilder = new ProcessBuilder(/* some args */);
proc = procBuilder.start();
if (proc.waitFor(30000, TimeUnit.MILLISECONDS))
{
//Etc...
}
else
{
//Handle it
}
}
catch (InterruptedException ie)
{
currentThread().interrupt();
}
finally
{
//What goes here?
}
I have tried to find some source that indicates whether it is required to call proc.destroy()
(should I check isAlive()
before calling destroy?), and to manually close its input/output/error streams, to no avail. Not even the official documentation makes this clear, from what I can tell.
Is it necessary, or even just good practice, to perform these operations when I am finished with the spawned process?
stdin
. – GreatcoatprocBuilder.inheritIO();
(before starting the process) to make it appear in the same place as your Java program’s output. – Homestretch