output redirect - How to execute system commands (linux/bsd) using Java -


I try to run cheap and run a local system command in Java ( uname -a ) I am doing I am looking to get output from uname and store it in string What is the best way to do this? Current code:

  public square lame {public static zero main (string array []) {try {process p = runtime.gettime (). Exec ("uname -a"); P.waitFor (); Buffer Reader = New buffed reader (neweststream reader (PJet InputStream ())); String line = reader Readline (); While (line! = Null) {System.out.println (line); Line = reader. Readline (); }} Catch (IOE Execution E1) {} Catch (Interrupted Expression E2) {} System. Out.printline ("end."); }}  

Your approach is not far away, which I want to do:

Runtime R = Runtime. Gratetime (); Process p = r.exec ("uname -a"); P.waitFor (); Buffettder B = new buffed reader (new input strieder reader (PJet InputStream ())); String line = ""; While ((line = breadlines ())! = Null {} System.out.println (line);} B. Close ();

Whatever exception you make, Take care.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -