Feedback on: irt.org FAQ Knowledge Base Q1486
Comments:
I can invoke a new process on MS Windows, but can't on Alpha Unix.
// ##############################
Runtime r = Runtime.getRuntime();
Process p = null;
//p = r.exec("ls -l > filelist.txt");
p = r.exec("D:\\WINNT\\notepad.exe ");
Length:
Too short
Comments:
If you want to grab the output from an executable then use the following code:
// You need the following imports...
import java.lang.System;
import java.lang.Runtime;
import java.io.IOException;
// The executable...
String strFile = "c:/test.exe";
// The output of the executable...
String strResult = "";
Process obProcess = null;
// Byte-Counter...
int intByte = -1;
// Runtime Environement
Runtime obRuntime = Runtime.getRuntime();
try
{
obProcess = obRuntime.exec( strFile );
InputStream obInputStream = obProcess.getInputStream();
intByte = obInputStream.read();
while ( intByte != -1 )
{
strResult += ( char ) intByte;
intByte = obInputStream.read();
}
}
catch ( Exception e )
{
System.out.println("Error : " + e);
}
System.out.println("strResult : " + strResult);