![]() |
|
|
|||||||
![]() |
Java - execute shell script from a java app |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Dear all
I'm able now to execute a shell script from my java application. But how can I get the results from the shell and safe them in variables? Lets say my shell scripts executes 'arch'. The return value would be 'i686'. How can I get this value in a String variable? Thanks Peter =?ISO-8859-1?Q?Peter_H=F6ltschi?= |
|
|
|
|
#2 |
|
Posts: n/a
|
Peter Höltschi wrote:
> I'm able now to execute a shell script from my java application. But how > can I get the results from the shell and safe them in variables? Lets > say my shell scripts executes 'arch'. The return value would be 'i686'. > How can I get this value in a String variable? Runtime.exec() returns a Process object. That allows you to get the standard output of the programm as an InputStream. Michael Borgwardt |
|
|
|
#3 |
|
Posts: n/a
|
> import java.io.*;
> > public class Test { > public static void main(String [] args) { > try { > Runtime rt = Runtime.getRuntime(); > Process ps = rt.exec("vi test.txt"); > OutputStream os = ps.getOutputStream(); > InputStream is = ps.getInputStream(); > DataOutputStream dos = new DataOutputStream(os); > dos.writeBytes("i"); > dos.writeBytes("test"); > dos.writeBytes("u001B"); > dos.writeBytes(":wq"); > dos.flush(); > ps.waitFor(); > dos.close(); > System.out.println(ps.exitValue()); > } > catch (Exception ex) > { > System.out.println(ex); > } > } > } Alex Kizub |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to execute an external software from VHDL? And how to interface VHDL with JAVA? | becool_nikks | Software | 0 | 03-06-2009 07:08 PM |
| Java Beginners | Still Bill | Software | 3 | 02-19-2008 10:13 AM |
| help with master page and java script | alain23 | Software | 0 | 09-20-2007 06:02 AM |
| converting java to applet | anub | Software | 0 | 09-11-2007 12:25 PM |
| DVD Verdict reviews: GHOST IN THE SHELL: STAND ALONE COMPLEX (VOLUME 1) and more! | DVD Verdict | DVD Video | 0 | 08-05-2004 10:03 AM |