Hello all,
I am trying to construct a program that tries to execute a command line statement inside a Java program. I have determined that the syntax below works well if the statement is valid (ie. runs a self contained c program). However, if the statement is invalid, there is nothing returned. For example, let's say the program bee is there. The statement will work and print out the output from running bee. However, if bee does not exist, I can not view the errors from within Java. The code I am using is :
try {
Process extProcess = rt.exec(compileField.getText());
extProcess.waitFor();
// receive the output of external program
InputStream extInput = extProcess.getInputStream();
int bytesAvailable = extInput.available();
if (bytesAvailable > 0)
{
byte[] extInputData = new byte[bytesAvailable];
extInput.read(extInputData);
System.out.println(new String(extInputData));
for (int i=0;i<bytesAvailable;i++) {
s+=(char)extInputData;
}
JOptionPane.showMessageDialog(null,s ,"testing it",JOptionPane.INFORMATION_MESSAGE);
outputS=s;
// System.exit(0);
}
}
catch (Exception e)
{
}
Can anybody help me. I want the user of my program to be able to see if a certain file exists or not. This means that the OS will output error messages if the program does not exist (which should be able to be captured by Java into a string)...there should be nothing output if the program does exist.
thanks
Brinker
I am trying to construct a program that tries to execute a command line statement inside a Java program. I have determined that the syntax below works well if the statement is valid (ie. runs a self contained c program). However, if the statement is invalid, there is nothing returned. For example, let's say the program bee is there. The statement will work and print out the output from running bee. However, if bee does not exist, I can not view the errors from within Java. The code I am using is :
try {
Process extProcess = rt.exec(compileField.getText());
extProcess.waitFor();
// receive the output of external program
InputStream extInput = extProcess.getInputStream();
int bytesAvailable = extInput.available();
if (bytesAvailable > 0)
{
byte[] extInputData = new byte[bytesAvailable];
extInput.read(extInputData);
System.out.println(new String(extInputData));
for (int i=0;i<bytesAvailable;i++) {
s+=(char)extInputData;
}
JOptionPane.showMessageDialog(null,s ,"testing it",JOptionPane.INFORMATION_MESSAGE);
outputS=s;
// System.exit(0);
}
}
catch (Exception e)
{
}
Can anybody help me. I want the user of my program to be able to see if a certain file exists or not. This means that the OS will output error messages if the program does not exist (which should be able to be captured by Java into a string)...there should be nothing output if the program does exist.
thanks
Brinker