Running external system command using RMI

Henry Tran <[email protected]> Wed, 28 Jun 2006 10:35:19 +1000
Newsgroups gmane.comp.java.sun.rmi
Message-ID <[email protected]>

Note: forwarded message attached.
 Send instant messages to your online friends http://au.messenger.yahoo.com

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html

  Dear Java Guru,

  I am at a lost as to why Java could not display the standard output of a Windows XP professional command "ipconfig" using the following modified version of the RMI tutorial that has worked in the past::

  HelloExternalClient exception: java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
        java.net.SocketException: Connection reset

  Please refer to further detail in the attached file "RMI External Command question.txt"

  Any assistance would be appreciated.
  Thanks,
  Netbeans Fan



 Send instant messages to your online friends http://au.messenger.yahoo.com

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html

Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Dear Java Guru,

  I am at a lost as to why Java could not display the standard output of a Windows XP professional command "ipconfig" using the following
  modified version of the RMI tutorial that has worked in the past:

HELLOEXTERNAL interface
-----------------------
  import java.rmi.*;
  public interface HelloExternalInterface extends Remote {
public void LocalRunCommandTest() throws RemoteException;
}

HELLOEXTERNAL class
-------------------
  import java.rmi.*;
import java.rmi.server.*;
import java.io.*;
  public class HelloExternal extends UnicastRemoteObject implements HelloExternalInterface {

    /** Creates a new instance of HelloExternal */
    public HelloExternal() throws RemoteException {
    }
    public void LocalRunCommandTest() throws RemoteException {
        String s = null;
        try {
        // run the Unix "ps -ef" command
            Process p = Runtime.getRuntime().exec("ipconfig");
            BufferedReader stdInput = new BufferedReader(new
                 InputStreamReader(p.getInputStream()));
            BufferedReader stdError = new BufferedReader(new
                 InputStreamReader(p.getErrorStream()));

            // read the output from the command
            System.out.println("Here is the standard output of the command:\n");
            while ((s = stdInput.readLine()) != null) {
                System.out.println(s);
            }

            // read any errors from the attempted command
            System.out.println("Here is the standard error of the command (if any):\n");
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }
            System.exit(0);
        }
        catch (IOException e) {
            System.out.println("exception happened - here's what I know: ");
            e.printStackTrace();
            System.exit(-1);
        }
    }
}

  HELLOEXTERNAL server
--------------------
  import java.rmi.*;
import java.lang.*;
  public class HelloExternalServer {

    /** Creates a new instance of HelloExternalServer */
    public HelloExternalServer() {
    }
   public static void main (String[] argv) {
     try {
         Naming.rebind ("HelloExternal", new HelloExternal());
         System.out.println ("HelloExternal Server is ready.");
     } catch (Exception e) {
         System.out.println ("HelloExternal Server failed: " + e);
     }
 }
}

HELLOEXTERNAL client class
--------------------------
  import java.rmi.*;
  public class HelloExternalClient {

    /** Creates a new instance of HelloExternalClient */
    public HelloExternalClient() {
    }
    public static void main (String [] argv) {
    try {
        HelloExternalInterface hello = (HelloExternalInterface) Naming.lookup ("//Localhost/HelloExternal");
        hello.LocalRunCommandTest();
    }
    catch (Exception e) {
    System.out.println ("HelloExternalClient exception: " + e);
    }
}
}

The following orders of running both HELLOEXTERNAL Client & HELLOEXTERNAL server are:
  ( i ) Run "start RMIREGISTRY" from c:\Document Settings\administrator\Learning Java\build\classes.
( ii ) Run HelloExternalServer class in Netbeans 5.0 with these output:
  init:
deps-jar:
compile-single:
run-single:
HelloExternal Server is ready.
  ( iii ) Run HelloExternalClient class in Netbeans 5.0 with these error message:
  init:
deps-jar:
compile-single:
run-single:
HelloExternalClient exception: java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
        java.net.SocketException: Connection reset
BUILD SUCCESSFUL (total time: 1 second)

  I am running Java JDK & JRE 1.5 update 6.0, Netbeans 5.0 on Windows XP professional platform.
  There are no RMI Registry or security problem. Windows XP firewall has been turned off.
  The LocalRunCommandTest() method has successfully display the standard ouput of "ipconfig" command on the same PC.
  All the above classes are running on the same PC.
  Not sure whether there needs to be certain IO buffer/wrapper required prior to displaying the standard output.
  Any assistance would be appreciated.

  Thanks,
  Netbeans Fan


---------------------------------
On Yahoo!7
  Answers: Real people ask and answer questions on any topic.

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html
RMI External Command question.txt (text/plain, 4.7 KB)
Dear Java Guru,

I am at a lost as to why Java could not display the standard output of a Windows XP professional command "ipconfig" using the following modified version of the RMI tutorial that has worked in the past:


HELLOEXTERNAL interface
-----------------------

import java.rmi.*;

public interface HelloExternalInterface extends Remote {
/**
 * Remotely invocable method.
 * @return the message of the remote object, such as "Hello, world!".
 * @exception RemoteException if the remote invocation files.
 */
 public void LocalRunCommandTest() throws RemoteException;
}


HELLOEXTERNAL class
-------------------

import java.rmi.*;
import java.rmi.server.*;
import java.io.*;

public class HelloExternal extends UnicastRemoteObject implements HelloExternalInterface {

    /** Creates a new instance of HelloExternal */
    public HelloExternal() throws RemoteException {
    }
    public void LocalRunCommandTest() throws RemoteException {
        String s = null;
        try {
            // run the Unix "ps -ef" command
            Process p = Runtime.getRuntime().exec("ipconfig");
            BufferedReader stdInput = new BufferedReader(new
                 InputStreamReader(p.getInputStream()));
            BufferedReader stdError = new BufferedReader(new
                 InputStreamReader(p.getErrorStream()));

            // read the output from the command
            System.out.println("Here is the standard output of the command:\n");
            while ((s = stdInput.readLine()) != null) {
                System.out.println(s);
            }

            // read any errors from the attempted command
            System.out.println("Here is the standard error of the command (if any):\n");
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }
            System.exit(0);
        }
        catch (IOException e) {
            System.out.println("exception happened - here's what I know: ");
            e.printStackTrace();
            System.exit(-1);
        }
    }
}



HELLOEXTERNAL server
--------------------

import java.rmi.*;
import java.lang.*;

public class HelloExternalServer {

    /** Creates a new instance of HelloExternalServer */
    public HelloExternalServer() {
    }
   public static void main (String[] argv) {
     try {
         Naming.rebind ("HelloExternal", new HelloExternal());
         System.out.println ("HelloExternal Server is ready.");
     } catch (Exception e) {
         System.out.println ("HelloExternal Server failed: " + e);
     }
 }
}


HELLOEXTERNAL client class
--------------------------

import java.rmi.*;

public class HelloExternalClient {

    /** Creates a new instance of HelloExternalClient */
    public HelloExternalClient() {
    }
    public static void main (String [] argv) {
    try {
        HelloExternalInterface hello = (HelloExternalInterface) Naming.lookup ("//Localhost/HelloExternal");
        hello.LocalRunCommandTest();
    }
    catch (Exception e) {
    System.out.println ("HelloExternalClient exception: " + e);
    }
}
}


The following orders of running both HELLOEXTERNAL Client & HELLOEXTERNAL server are:

( i ) Run "start RMIREGISTRY" from c:\Document Settings\administrator\Learning Java\build\classes.
( ii ) Run HelloExternalServer class in Netbeans 5.0 with these output:

init:
deps-jar:
compile-single:
run-single:
HelloExternal Server is ready.

( iii ) Run HelloExternalClient class in Netbeans 5.0 with these error message:

init:
deps-jar:
compile-single:
run-single:
HelloExternalClient exception: java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
        java.net.SocketException: Connection reset
BUILD SUCCESSFUL (total time: 1 second)



I am running Java JDK & JRE 1.5 update 6.0, Netbeans 5.0 on Windows XP professional platform.

There are no RMI Registry or security problem. Windows XP firewall has been turned off.

The LocalRunCommandTest() method has successfully display the standard ouput of "ipconfig" command on the same PC.

All the above classes are running on the same PC.

Not sure whether there needs to be certain IO buffer/wrapper required prior to displaying the standard output.

Any assistance would be appreciated.

Thanks,

Netbeans Fan

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html