Runtime might not recognize Unix pipe, you need to do it like:

Process p = Runtime.getRuntime().exec(new String[] {"/bin/sh","-c", "tnsping
emsd | grep Host"}); 

Richard Ji

-----Original Message-----
Sent: Monday, December 09, 2002 11:29 AM
To: Multiple recipients of list ORACLE-L


Good Morning.

I am trying to get the output of a server process executed by java
via Runtime.exec().  Here's the code:

import java.sql.*;
import java.io.*;

public class ip {

  public static void main (String args []) {

    Runtime r = Runtime.getRuntime();

    try {
      String  sid = "emsd";
      String cmd1 = "tnsping " + sid + " | grep 'Host' | cut -d' ' -f18 |
cut -d')' -f1";
      System.out.println(cmd1);
      Process p = Runtime.getRuntime().exec(cmd1); 
      int exitValue = p.waitFor();
      System.out.println(p);
      BufferedReader br = new BufferedReader(new
InputStreamReader(p.getInputStream())); 
      String ip = br.readLine();
      System.out.println(ip);

    } catch (Exception e) {
        System.out.println("Generic Exception catch.");
    }
  } // end of main()
}

When I execute it I get:
tnsping emsd | grep 'Host' | cut -d' ' -f18 | cut -d')' -f1
java.lang.UNIXProcess@5988f

The output of the command line is:
128.100.1.140

Anyone see what I'm missing?
Just to make this somewhat oracle related...this is part of a hot backup
script.
I am trying to grep the ip (and ultimately port) of the listener so I can 
dynamically generate the connect to the database. :)

Thanks,

John P Weatherman
Database Administrator
Replacements Ltd.
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: John Weatherman
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Richard Ji
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

Reply via email to