Problem in executing a Java program using runexec
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Shweta_Bhargava
Posted On:   Friday, September 1, 2006 02:12 PM

Hi, Heres the code...===================== import java.io.*; public class RunCommand { public static void main(String args[]) { String s = null; try { // run the Unix "ps -ef" command Process p = Runtime.getRuntime().exec("ps -ef"); 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) { Syste   More>>

Hi,


Heres the code...=====================





import java.io.*;

public class RunCommand {

public static void main(String args[]) {

String s = null;

try {

// run the Unix "ps -ef" command

Process p = Runtime.getRuntime().exec("ps -ef");

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



This seems to be throwing continous error :======


java.io.IOException: CreateProcess: ps -ef error=2
exception happened - here's what I know:
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process. (Win32Process.java:87)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:582)
at java.lang.Runtime.exec(Runtime.java:446)
at java.lang.Runtime.exec(Runtime.java:389)
at java.lang.Runtime.exec(Runtime.java:353)



I work on windows XP and need to execute certain commands of AIX... BUt looks like, it doesnt work !


Please help ... need the solution urgently.

   <<Less

Re: Problem in executing a Java program using runexec

Posted By:   Robert_Lybarger  
Posted On:   Friday, September 1, 2006 05:04 PM

I work on windows XP and need to execute certain commands of AIX... BUt looks like, it doesnt work ! Please help ... need the solution urgently.

Clearly the solution is you need to install AIX on your Windows XP box?

Re: Problem in executing a Java program using runexec

Posted By:   Anonymous  
Posted On:   Friday, September 1, 2006 02:57 PM

Um..You are on Windows XP and you are surprised you can't run a Unix command?
About | Sitemap | Contact