• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

More Help needed on Runtime.exec

 
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.
 
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!