Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Another Java Question

RE: Another Java Question

From: John Weatherman <john.weatherman_at_replacements.com>
Date: Tue, 10 Dec 2002 05:29:08 -0800
Message-ID: <F001.00515F70.20021210052908@fatcity.com>


Richard,

Thanks, that got it.

John P Weatherman
Database Administrator
Replacements Ltd.

-----Original Message-----
Sent: Monday, December 09, 2002 4:40 PM
To: Multiple recipients of list ORACLE-L

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_at_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: john.weatherman_at_replacements.com

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: ListGuru_at_fatcity.com (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: richard.ji_at_mobilespring.com
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: ListGuru_at_fatcity.com (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: John Weatherman
  INET: john.weatherman_at_replacements.com
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: ListGuru_at_fatcity.com (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). Received on Tue Dec 10 2002 - 07:29:08 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US