This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!

CSLA Sanchez

Greenhorn
+ Follow
since Feb 07, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by CSLA Sanchez

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!
17 years ago
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.
17 years ago
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.
17 years ago
Thank you all for your help. Based on your advice, the following subtitution does what I want to do:
Process proc = runtime.exec("cmd /c dir");
And it works like a charm! I will try the other solution which involves Java native options.
THANKS!!
--Cecilia.
17 years ago
Dear Developers:
Can you tell me if I am doing anything wrong with the following code? I am trying to get DIR results using runtime.exec. I am using JBuilder 9:
System.out.println("Hello World!");
Runtime runtime = Runtime.getRuntime();
try{
Process proc = runtime.exec("dir"); // like the dir command at DOS prompt
System.out.println(proc);
InputStream inputstream = proc.getInputStream();
InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
// read the ls output
String line;
while ((line = bufferedreader.readLine()) != null) {
System.out.println(line);
}
}catch(IOException e){}
System.out.println("Good BYE");
With the above I get results for the first and last System.out.println, but nothing in the middle. i would like to see what are the dir contents of the directory. Any hints?
Also, I tried to run the program from the commad line, and I get the .java file to compile using javac, but when I try to execute the class using "java" this is what I get:
"Exception in thread "main" java.lang.NoClassDefFoundError" and something else.
Any ideas?
Thanks in advance!
17 years ago