Re: [exec] Using Commons Exec for context-sensitive execution
Bernd Eckenfels wrote > Hello, > > did you try to write actual line endings? > > I tested your code and it worked on Windows (cygwin bash) after adding > \n like: > > os.write("export MY_VAR=test\n"); > os.flush(); > os.write("echo myvar:$MY_VAR\n"); > > Gruss > Bernd Thanks, that made the trick. Bernd Eckenfels wrote > I also think the use of the common-executor makes this whole stuff > unecesary complicated. Especially if the alternative is a Java7 with > ProcessBuilder and redirectOutput(); Yea, can't agree more -- View this message in context: http://apache-commons.680414.n4.nabble.com/exec-Using-Commons-Exec-for-context-sensitive-execution-tp4661652p4661706.html Sent from the Commons - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [exec] Using Commons Exec for context-sensitive execution
Hello, did you try to write actual line endings? I tested your code and it worked on Windows (cygwin bash) after adding \n like: os.write("export MY_VAR=test\n"); os.flush(); os.write("echo myvar:$MY_VAR\n"); Gruss Bernd I also think the use of the common-executor makes this whole stuff unecesary complicated. Especially if the alternative is a Java7 with ProcessBuilder and redirectOutput(); Am Wed, 2 Apr 2014 01:54:30 -0700 (PDT) schrieb yalmasri : > posting to fix the formatting on other mailing archives > > > > -- > View this message in context: > http://apache-commons.680414.n4.nabble.com/exec-Using-Commons-Exec-for-context-sensitive-execution-tp4661652p4661653.html > Sent from the Commons - User mailing list archive at Nabble.com. > > - > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > For additional commands, e-mail: user-h...@commons.apache.org > - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [exec] Using Commons Exec for context-sensitive execution
posting to fix the formatting on other mailing archives -- View this message in context: http://apache-commons.680414.n4.nabble.com/exec-Using-Commons-Exec-for-context-sensitive-execution-tp4661652p4661653.html Sent from the Commons - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
[exec] Using Commons Exec for context-sensitive execution
What I'm trying to do is simply run a batch file that does some preparatory work necessary for the subsequent commands to be executed successfully (setting environment variables and stuff). To prove this I put together a sample that uses Commons Exec publicclassTester{publicstaticvoidmain(String[]args)throwsException{Testertester =newTester();MyResultHandlerhandler =tester.newMyResultHandler();CommandLinecommandLine =CommandLine.parse("bash");PipedOutputStreamps =newPipedOutputStream();PipedInputStreamis =newPipedInputStream(ps);BufferedWriteros =newBufferedWriter(newOutputStreamWriter(ps));Executorexecutor =newDefaultExecutor();PumpStreamHandlerioh =newPumpStreamHandler(System.out,System.err,is);executor.setStreamHandler(ioh);ioh.start();executor.execute(commandLine,handler);os.write("export MY_VAR=test");os.flush();os.write("echo $MY_VAR");os.flush();os.close();}privateclassMyResultHandlerextendsDefaultExecuteResultHandler{@OverridepublicvoidonProcessComplete(finalintexitValue){super.onProcessComplete(exitValue);System.out.println("\nsuccess");}@OverridepublicvoidonProcessFailed(finalExecuteExceptione){super.onProcessFailed(e);e.printStackTrace();}}}But that prints empty string instead of the word "test". Any clues?