output on stderr disappears when using gcj in a script?
Erik Poupaert
erik.poupaert@skynet.be
Thu Mar 25 19:34:00 GMT 2004
Hi,
By the way, I forgot to mention something. The script is not executed directly by
bash, but by a gcj program.
It reads the stderr output from the script and outputs it to system.out.
So the problem, could be with java.lang.Runtime. The funny thing is, that it always
used to work with previous versions of gcj and bash. I've been using the same program
to do these things for more than a year now, compiling tens of source trees, and it
always worked properly; and now it starts failing (on producing the output from
stderr correctly).
Greetings
Erik
--------------
Invokation:
--------------
String cmdExec[]={Command.EXE_BASH,pCommandArgs.getLocations().getScript2FilePath()};
Process process=Runtime.getRuntime().exec(cmdExec);
ProcessInputStreamThread threadErr=
new ProcessInputStreamThread(process.getErrorStream(),
ProcessInputStreamThread.STREAMTYPE_ERROR);
threadErr.start();
int exitValue=process.waitFor();
--------------------------------
ProcessInputStreamThread
--------------------------------
public class ProcessInputStreamThread extends Thread
{
//===========================================================
//CONSTANTS
//===========================================================
public static final int STREAMTYPE_OUTPUT=1;
public static final int STREAMTYPE_ERROR=2;
public static final String STREAMTYPE_OUTPUT_STRING="out";
public static final String STREAMTYPE_ERROR_STRING="err";
public static final String STREAMTYPE_UNKNOWN_STRING="unknown";
//===========================================================
//VARIABLES
//===========================================================
protected InputStream mInputStream;
protected int mStreamType;
//===========================================================
//CONSTRUCTOR
//===========================================================
/**
* Constructs a new process inputstream thread.
*/
public ProcessInputStreamThread(InputStream pInputStream, int pStreamType)
{
mInputStream=pInputStream;
mStreamType=pStreamType;
}
//===========================================================
//GET STREAM TYPE STRING
//===========================================================
protected String getStreamTypeString()
{
if(mStreamType==STREAMTYPE_OUTPUT) return STREAMTYPE_OUTPUT_STRING;
else if(mStreamType==STREAMTYPE_ERROR) return STREAMTYPE_ERROR_STRING;
else return STREAMTYPE_UNKNOWN_STRING;
}
//===========================================================
//RUN
//===========================================================
public void run()
{
try
{
BufferedReader bashReader=
new BufferedReader(new InputStreamReader(mInputStream));
String bashOutputLine = bashReader.readLine();
String streamType=getStreamTypeString();
while (bashOutputLine!=null)
{
System.out.println(streamType+">"+bashOutputLine);
System.out.flush();
bashOutputLine = bashReader.readLine();
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
More information about the Java
mailing list