Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

getRuntime().exec()

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may help:

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic