• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

getRuntime().exec()

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I am trying to call command of cygwin...the input file is from my java codes and i wanna get the output to java...but it seems i even cant make the command run...i appreciate if someone could help me out..thanks... I use the following codes to test to redirect the output to a file..but it doesnt work ..

import java.io.*;

public class ExectTest {

public static void main(String argv[]) {

try {
String ls_str;
String[] cmd = {"c:/cygwin/bin/ls", ">output.dat"};
Process proc = Runtime.getRuntime().exec(cmd);

DataInputStream ls_in = new DataInputStream(ls_proc.getInputStream());

try {
while ((ls_str = ls_in.readLine()) != null) {
System.out.println(ls_str);

}
} catch (IOException e) {
System.exit(0);
}

} catch (IOException e1) {
System.err.println(e1);
System.exit(1);
}

System.exit(0);
}
}
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) You'll need to rename ls_proc to just proc to make it compile.
2) I have no idea why it doesn't work, I just ran a little test, trying send the output from ping to file but that didn't work.
 
Ranch Hand
Posts: 147
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!