Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

More Help needed on Runtime.exec

 
CSLA Sanchez
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 799
5
 
CSLA Sanchez
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic