Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply

Java - execute shell script from a java app

 
Thread Tools Search this Thread
Old 12-03-2004, 07:06 PM   #1
=?ISO-8859-1?Q?Peter_H=F6ltschi?=
 
Posts: n/a
Default execute shell script from a java app

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
  Reply With Quote
Old 12-03-2004, 08:23 PM   #2
Michael Borgwardt
 
Posts: n/a
Default Re: execute shell script from a java app

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.
  Reply With Quote
Old 12-04-2004, 05:31 PM   #3
Alex Kizub
 
Posts: n/a
Default Re: execute shell script from a java app

> 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);
> }
> }
> }


  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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 06:08 PM
Java Beginners Still Bill Software 3 02-19-2008 09:13 AM
help with master page and java script alain23 Software 0 09-20-2007 05:02 AM
converting java to applet anub Software 0 09-11-2007 11:25 AM
DVD Verdict reviews: GHOST IN THE SHELL: STAND ALONE COMPLEX (VOLUME 1) and more! DVD Verdict DVD Video 0 08-05-2004 09:03 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47