You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stream feeder and consumer threads should be replaced with ProcessBuilder->inheritIO to allow child processes to die/be killed on Windows when hitting CTRL-C
#59
Open
jjYBdx4IL opened this issue
Jan 31, 2019
· 3 comments
I played around with plexus-utils to find out why my own test case works, but plexus-utils doesn't. Answer: it seems to be related to the stream pumpers/feeders. When I replace Runtime.exec() with ProcessBuilder and use its inheritIO() instead, the child process goes away as expected when the parent process calls Process->destroy() on it. Specifically using Redirect.INHERIT on the child's STDIN fixes the issue.
Commandline:
/**
* Executes the command.
*/
public Process execute()
throws CommandLineException
{
// TODO: Provided only for backward compat. with <= 1.4
verifyShellState();
Process process;
// addEnvironment( "MAVEN_TEST_ENVAR", "MAVEN_TEST_ENVAR_VALUE" );
String[] environment = getEnvironmentVariables();
File workingDir = shell.getWorkingDirectory();
ProcessBuilder pb = new ProcessBuilder(getCommandline());
pb.directory(workingDir);
pb.inheritIO();
if (environment != null) {
for (String s : environment) {
String[] kv = s.split("=", 2);
pb.environment().put(kv[0], kv[1]);
}
}
try
{
if ( workingDir != null ) {
if ( !workingDir.exists() )
{
throw new CommandLineException( "Working directory \"" + workingDir.getPath()
+ "\" does not exist!" );
}
else if ( !workingDir.isDirectory() )
{
throw new CommandLineException( "Path \"" + workingDir.getPath()
+ "\" does not specify a directory." );
}
}
process = pb.start();
}
catch ( IOException ex )
{
throw new CommandLineException( "Error while executing process.", ex );
}
return process;
}
The text was updated successfully, but these errors were encountered:
While fixing gwt-maven-plugin, I found it easier to just use ProcessBuilder there. Do you think the command line exec stuff in plexus-utils is still necessary as of Java 7?
tbroyer/gwt-maven-plugin#110 (comment)
I played around with plexus-utils to find out why my own test case works, but plexus-utils doesn't. Answer: it seems to be related to the stream pumpers/feeders. When I replace Runtime.exec() with ProcessBuilder and use its inheritIO() instead, the child process goes away as expected when the parent process calls Process->destroy() on it. Specifically using Redirect.INHERIT on the child's STDIN fixes the issue.
Commandline:
The text was updated successfully, but these errors were encountered: