wood burning stoves 2.0*
The moose likes Java in General and the fly likes More Help needed on Runtime.exec   Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "More Help needed on Runtime.exec   " Watch "More Help needed on Runtime.exec   " New topic
Author

More Help needed on Runtime.exec

CSLA Sanchez
Greenhorn

Joined: Feb 07, 2004
Posts: 5
Dear Developers,
I gave up trying to use directly Runtime.exec as follows:
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("cmd /c ss dir -R > resultFile.txt");
In which "ss" is a Visual Source Safe command line executalble. "dir" is the command passed to such and executable. BTW, I did omit the "cmd /c" portion with no results. ss is in the path.
So, on a Windows 2000 system, I decided to create a batch file with the command I needed and worked like a charm.
Process proc = runtime.exec("cmd /c AnScript.bat");

I moved everything to a "different" Windows 2000 system and I get an error, the .bat file gets called, but the ss command in it does bring up an error!! I can perfectly execute the AnScript.bat directly at the DOS prompt, (or windows explorer), but from withing the Java it is just not possible. Instead of using the ss command I used something different in the .bat file (like echo hello there > hello.txt) and that does work. But the ss does not.
Why is that I can run the .bat from the command line with no problems? And why java does not take it?
why does Java take it on the other Windows 2000 machine? ss is in the path on both machines.
Please help,
--Cecilia.
Jeff Langr
author
Ranch Hand

Joined: May 14, 2003
Posts: 762
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html


Books: Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
CSLA Sanchez
Greenhorn

Joined: Feb 07, 2004
Posts: 5
Thank you! I used listing 4.8 and StreamGobbler and now the script .bat file runs as is suppossed to. Nevertheless, I still don't understand why this redirection worked because the redirect was inside the .bat script, and not directly was the argument of Runtime.exec(), and the fact that under a different Windows 2000 machine the scricpt worked without having to use the solution in 4.8
I am so happy it works now!
Thanks again!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: More Help needed on Runtime.exec