• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Runtime.exec problems

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Developers,
Hope you can help with the following:
I can successfully get the "dir" contents in the same way I do at the DOS prompt by doing the following:
Runtime runtime = Runtime.getRuntime();

Process proc = runtime.exec("cmd /c dir");
I can also run a perl script via:
Process proc = runtime.exec("cmd /c perl MyPerl.pl");
HOWEVER, the command I need to run is "ss.exe" which is part of VisualSource Safe. At the command prompt, I use this command with the "dir" argument to get a directory listing of the current Visual SourceSafe Database as follows:
c:\temp>ss dir
and I get the results in here.
For some reason, this does not work in Java:
Process proc = runtime.exec("cmd /c ss dir");
I do not get an exception by doing this, and I tried to redirect the output to a file by:
Process proc = runtime.exec("cmd /c ss dir > out.txt");
The file "out.txt" gets created, but it is empty!!
How could I invoke Visual Source Safe command line arguments via Runtime.exe??
Thanks!
--Cecilia.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've always had better luck running a .bat file than the actual command. I suspect the problem is that 'ss.exe' is not a recognized command to the process that runs it. It works from dos because you have path variables set. When you try it again type the full path to the executable whether you use a .bat file or not this may help.
Also, if you don't wait for it to finish before closing things this could be a problem as well.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with all Lu's points. Additionally, there may be an error message being generated but not read. Process has a getError() method which allows you to read this. It's often easier to redirect the error output to a file, much like you've done for standard output:

Or send everything to the same file:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic