> I want to get cpu stats of the remote machine ,for this i'm using:
> Process p=Runtime.getRuntime('rsh mac01 "iostat -t 5"');
Did you try to compile that?
> but it is not recognizing the rsh and giving error as given in my first
> post.
Which error? Which post?
> Please tell me what to do?
Show us the code that you are actually using together with the error message.
> I want to get cpu stats of the remote machine ,for this i'm using:
> Process p=Runtime.getRuntime('rsh mac01 "iostat -t 5"');
> but it is not recognizing the rsh and giving error as given in my first
> post.
None of your posts in this thread say what the error is.
The line of code in your example here will not compile (for more than
one reason). Please post the *real* code you need help with, and the
*real* error messages you get. Use cut-and-paste.
If rsh is not recognized, then you likely need to specify a complete
path like /bin/rsh or /usr/bin/rsh.
Note that if you need to use quoting in the command line, you need to
use the version of exec() that takes an array of Strings. Don't add
any extra quotation marks, the grouping is implied by the array
structure, like this:
String[] cmd = {
"/usr/bin/rsh",
"mac01",
"iostat -t 5",
};
Process p = Runtime.getRuntime().exec(cmd);
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
ruds - 08 Sep 2006 05:40 GMT
Thanks everyone for replying and Sorry for not posting the code.
Heres the code :
Process p = Runtime.getRuntime().exec("rsh mac5 ps");
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:
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);
}//end of try
catch (IOException e)
{
System.out.println("exception occured");
e.printStackTrace();
System.exit(-1);
}
I'm able to execute rsh but i'm not getting the $ prompt .
Also ps does not execute properly its giving o/p as:
PID TTY TIME CMD
Thats it.
Can u tell what is the problem and where i'm going wrong???
thanks in advance.
Gordon Beaton - 08 Sep 2006 07:24 GMT
> I'm able to execute rsh but i'm not getting the $ prompt .
Not a Java issue. You won't ever get a prompt if you specify a command
for rsh to run on the remote. The two are mutually exclusive: if you
want a prompt, don't specify a command. Try it from a command shell.
> Also ps does not execute properly its giving o/p as:
> PID TTY TIME CMD
>
> Thats it.
> Can u tell what is the problem and where i'm going wrong???
Also not a Java issue. Try running this rsh command in a command
shell, and see if it works any differently.
Presumably there were no processes running that ps without arguments
shows by default. Try specifying some arguments, like "ps ax" or
"ps -ef" to see more.
To bring this back on topic for the group: don't first read all of
stdout and then all of stderr. You need to read both at the same time
while the program is running. Otherwise a program that produces a lot
of output to stderr will hang, and your program will deadlock while
you wait for stdout to reach EOF.
To solve this you need to either use a second thread (to read stderr),
or use ProcessBuilder and specify redirectErrorStream(true).
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
ruds - 08 Sep 2006 09:53 GMT
Thanks all of u for helping me.