[ https://issues.apache.org/jira/browse/EXEC-45?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sebb closed EXEC-45. -------------------- > Error while executing a command like echo > ----------------------------------------- > > Key: EXEC-45 > URL: https://issues.apache.org/jira/browse/EXEC-45 > Project: Commons Exec > Issue Type: Bug > Affects Versions: 1.0.1 > Environment: OS: Windows XP SP3 > Reporter: varma > > Hello, > After looking at the javaDoc for DefaultExecutor, I've tried a simple command > that 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: > {code:title=CommandExec.java|borderStyle=solid} > public final void executeEcho() > { > try > { > final CommandLine command = new CommandLine( "echo someValue" ); > command.addArgument( "> c:\test.txt" ); > final DefaultExecutor executor = new DefaultExecutor(); > final int value = executor.execute( command ); > System.out.println(value); > } > catch(Exception e) > { > e.printStackTrace(); > } > } > {code} > Exception being thrown: > {code:title=exception} > java.io.IOException: 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(Java13CommandLauncher.java:58) > at > org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:246) > at > org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:302) > at > org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:149) > at > org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:136) > at testing.CommandExex.main(CommandExex.java:15) > Caused by: java.io.IOException: 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 > {code} > From DefaultExecutor's JavaDoc: > {code} > Executor exec = new DefaultExecutor(); > CommandLine cl = new CommandLine("ls -l"); > int exitvalue = exec.execute(cl); > {code} -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.