I want to run a java program using a button on the GUI. I have used
the following code
try{
System.out.println("Inside execution");
Runtime.getRuntime().exec("cmd.exe");
System.out.println(command);
process= new ProcessBuilder(command);
process.start();
}
catch(Exception except)
{
except.printStackTrace();
}
The purpose is to launch a separate execution window a part from the
cmd.exe thats open through the GUI. When I did this using process
builder,the output would come but not in a separate execution window.
Moreover, the output was not complete and the println statements were
not getting displayed.
gethostbyname@gmail.com - 09 Mar 2007 19:42 GMT
On 9 mar, 14:53, misbah.muba...@gmail.com wrote:
> I want to run a java program using a button on the GUI. I have used
> the following code
[quoted text clipped - 14 lines]
> Moreover, the output was not complete and the println statements were
> not getting displayed.
Please, post your complete code. What about command and process
variables?
You could use System.err to get the println statements displayed. No?
gethostbyname
gethostbyname@gmail.com - 09 Mar 2007 19:46 GMT
On 9 mar, 14:53, misbah.muba...@gmail.com wrote:
> I want to run a java program using a button on the GUI. I have used
> the following code
[quoted text clipped - 14 lines]
> Moreover, the output was not complete and the println statements were
> not getting displayed.
You could use System.err to get the println statements displayed.
gethostbyname
gethostbyname@gmail.com - 09 Mar 2007 20:29 GMT
On 9 mar, 14:53, misbah.muba...@gmail.com wrote:
> I want to run a java program using a button on the GUI. I have used
> the following code
[quoted text clipped - 14 lines]
> Moreover, the output was not complete and the println statements were
> not getting displayed.
I think I understood your problem now. Would you like "redirect" the
output stream of external process?
********
package javaapplication2;
import java.awt.*;
import java.io.*;
import javax.swing.*;
/**
*
* @author gethostbyname
*/
public class Main {
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ProcessBuilder process;
try{
String command = "c:\\WINDOWS\\system32\\rasdial.exe";
InputStream in =
Runtime.getRuntime().exec(command).getInputStream();
String linha;
BufferedReader entrada = new BufferedReader(new
InputStreamReader(in));
while ((linha = entrada.readLine()) != null) {
System.out.println(linha);
}
entrada.close();
process = new ProcessBuilder(command);
process.start();
}
catch(Exception except)
{
except.printStackTrace();
}
}
}
********
gethostbyname