File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Runtime.exec problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Runtime.exec problems" Watch "Runtime.exec problems" New topic

Runtime.exec problems

CSLA Sanchez

Joined: Feb 07, 2004
Posts: 5
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");
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??
Lu Battist
Ranch Hand

Joined: Feb 17, 2003
Posts: 104
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.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
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:

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Runtime.exec problems
It's not a secret anymore!