Description
Hi,
Upgrading plexus-utils from 3.0.15 to last version in some application using Commandline occurs problems on Windows for executed binaries when on Windows PATH.
With v3.0.24, this snippet (not the best stream management, this is just a sample):
String bin = "mvn";
String arg = "-version";
Commandline cmd = new Commandline();
cmd.setExecutable( bin );
cmd.createArg().setValue( arg );
Process p = cmd.execute();
p.waitFor();
System.out.println( "Out: " + IOUtil.toString( p.getInputStream() ) );
System.out.println( "Err: " + IOUtil.toString( p.getErrorStream() ) );
Fails with (tested with java 1.7.0_51, 1.8.0_31, 1.8.0_91):
Exception in thread "main" org.codehaus.plexus.util.cli.CommandLineException: Error while executing process.
at org.codehaus.plexus.util.cli.Commandline.execute(Commandline.java:675)
at Main.main(Main.java:21)
Caused by: java.io.IOException: Cannot run program "mvn": CreateProcess error=2, Le fichier spécifié est introuvable
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at org.codehaus.plexus.util.cli.Commandline.execute(Commandline.java:655)
... 1 more
Caused by: java.io.IOException: CreateProcess error=2, Le fichier spécifié est introuvable
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 3 more
Same with cmd embedded command:
String bin = "echo";
String arg = "foo";
NB: These snippets worked fine in v3.0.15 (or in pure cmd command-line).
Is there some upgrades to do for this code continuing to work ? (Environment items to fill, ...)
I have tried to use cmd.addSystemEnvironment();
(containing PATH), but no change.
I'm not able to establish if it should be considered as a bug or not, because executing all plexus-utils unit tests (on Windows 10) for :
- v3.0.15, all works (with UT Fix : Quote Java binary when contain space (on Windows) #16).
- v3.0.25-SNAPSHOT: some fails, mainly on CommandlineTest :
Some fails are similar to my PATH binary execution problem:
testExecute(org.codehaus.plexus.util.cli.CommandlineTest)
junit.framework.AssertionFailedError: Error while executing process.
testDollarSignInArgumentPath(org.codehaus.plexus.util.cli.CommandlineTest)
java.lang.Exception: Unable to execute command: Error while executing process.
Some others seems more to be a forgot unit test expected results update about quotes management improvements (perhaps except the last/third):
testGetShellCommandLineBash(org.codehaus.plexus.util.cli.CommandlineTest)
junit.framework.ComparisonFailure: expected:<[\bin\echo] 'hello world'> but was:<['\bin\echo'] 'hello world'>
testGetShellCommandLineNonWindows(org.codehaus.plexus.util.cli.CommandlineTest)
junit.framework.ComparisonFailure: expected:<[\usr\bin a b]> but was:<['\usr\bin' 'a' 'b']>
testGetShellCommandLineBash_WithSingleQuotedArg(org.codehaus.plexus.util.cli.CommandlineTest)
junit.framework.ComparisonFailure: expected:<[\bin\echo 'hello world]'> but was:<['\bin\echo' ''"'"'hello world'"'"']'>
I could work on PR (fix or UT update), but some opinion/feedback/advice would be useful.
Thanks in advance.
Best regards