Hello,
I have been working on a problem that involves executing a command line statement in java such as gcc -c fileName. I want to capture the screen output (ie. errors, success) which generally appears as text such as :
compile successful
or
Error in line 23
Since these commands do not work in a window, but appear as lines in the OS display, is there a way to capture them. The following syntax does not work:
----------------------------------------------------------------------------------
Process extProcess=rt.exec(cmd);
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.out.println("\nFile Compiled Successfully"
// System.exit(0);
}
------------------------------------------------------------------------
probably because jave sees no bytes available. I have tried creating a command shell using '/c', but this does not help.
I have been working on a problem that involves executing a command line statement in java such as gcc -c fileName. I want to capture the screen output (ie. errors, success) which generally appears as text such as :
compile successful
or
Error in line 23
Since these commands do not work in a window, but appear as lines in the OS display, is there a way to capture them. The following syntax does not work:
----------------------------------------------------------------------------------
Process extProcess=rt.exec(cmd);
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.out.println("\nFile Compiled Successfully"
// System.exit(0);
}
------------------------------------------------------------------------
probably because jave sees no bytes available. I have tried creating a command shell using '/c', but this does not help.