commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "varma (JIRA)" <>
Subject [jira] Created: (EXEC-45) Error while executing a command like echo
Date Tue, 23 Mar 2010 13:01:27 GMT
Error while executing a command like echo

                 Key: EXEC-45
             Project: Commons Exec
          Issue Type: Bug
    Affects Versions: 1.0.1
         Environment: OS: Windows XP SP3
            Reporter: varma
            Priority: Blocker

After looking at the javaDoc for DefaultExecutor, I've tried a simple command the does an
"echo" and re-direct the output to a file. But, I'm getting "IOException". Not sure what I
am missing here or is it possible to execute a command directly without specifying the path
to an executable? I appreciate your help.

This is what I'm trying:
public final void executeEcho()
         final CommandLine command = new CommandLine( "echo someValue" );
         command.addArgument( "> c:\test.txt" );

         final DefaultExecutor executor = new DefaultExecutor();
         final int value = executor.execute( command );
      catch(Exception e)

Exception being thrown:
{code:title=exception} Cannot run program "echo someValue": CreateProcess error=2, The system
cannot find the file specified
	at java.lang.ProcessBuilder.start(Unknown Source)
	at java.lang.Runtime.exec(Unknown Source)
	at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(
	at org.apache.commons.exec.DefaultExecutor.launch(
	at org.apache.commons.exec.DefaultExecutor.executeInternal(
	at org.apache.commons.exec.DefaultExecutor.execute(
	at org.apache.commons.exec.DefaultExecutor.execute(
	at testing.CommandExex.main(
Caused by: CreateProcess error=2, The system cannot find the file specified
	at java.lang.ProcessImpl.create(Native Method)
	at java.lang.ProcessImpl.<init>(Unknown Source)
	at java.lang.ProcessImpl.start(Unknown Source)
	... 8 more

>From DefaultExecutor's JavaDoc:
Executor exec = new DefaultExecutor();
CommandLine cl = new CommandLine("ls -l");
int exitvalue = exec.execute(cl);

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message