[ 
https://issues.apache.org/jira/browse/EXEC-95?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15104863#comment-15104863
 ] 

Aleksandr Dubinsky commented on EXEC-95:
----------------------------------------

Thanks for the quick attention

 - In brief testing, WinNTCommandLauncher works.
 - However, I am worried by the call `newCmd.addArguments(newCmdArray);` which 
resets the value of `handleQuoting`
 - Is there a reason for using "cmd /c cd /d <working dir> && <command>" 
instead of just "cmd /c <command>"? The latter works as well, if not for a bug 
on line 64 of the original `WinNTCommandLauncher`. Instead of `return 
exec(newCmd, env);` it should have been `return super.exec(newCmd, env, 
workingDir)` (this method would have to be created in CommandLauncherProxy or 
WinNTCommandLauncher should inherit from Java13CommandLauncher like 
VmsCommandLauncher does).

 - I would not touch Java13CommandLauncher. You have chosen to override the 
OS's executable resolution policy, and this is a potentially dangerous move. 
Certainly it will surprise some users because it changes how Linux normally 
searches for executables. An executable without a directory path in front of it 
(eg "ping" instead of "./ping") must exist on the PATH, and will not be 
searched for in the working directory. However, your code does look for it in 
the current directory. This might even cause a security issue. I agree that 
given Java's philosophy it might make sense to actually standardize this aspect 
across platforms, and that the exception a user who forgets to write put "./" 
sees ("Cannot run program "ping2" (in directory "/home/user/")") is misleading. 
Yet, I would lean against this change as too dangerous. For example, you use 
the method `isFile` which will miss symlinks and cause problems on Linux.
 - In CommandLauncherFactory I would detect running on Windows and return a 
WinNTCommandLauncher.

> Program not found after setWorkingDirectory
> -------------------------------------------
>
>                 Key: EXEC-95
>                 URL: https://issues.apache.org/jira/browse/EXEC-95
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.3
>         Environment: win7 64 bit.
>            Reporter: Lorenzo Cozza
>            Assignee: Siegfried Goeschl
>
> I would like to run my script from a different folder, so I tried to use the 
> following line of code:
> String path = "C:/user/script/";
> CommandLine cmdLine = CommandLine.parse("myscript.cmd");
> DefaultExecutor executor = new DefaultExecutor();
> executor.setWorkingDirectory(new File(path));
> int exitValue = executor.execute(cmdLine);
> but I got an exception.
> I am using the following workaround:
> CommandLine cmdLine = CommandLine.parse(path+"/myscript.cmd");
> and it's working fine.
> The question is: are Executor and CommandLine related?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to