java.lang.Process.waitFor()

Erik Poupaert erik.poupaert@freestyler-toolkit.org
Sun Sep 28 12:38:00 GMT 2003


> Why not simply wait on an object with "synchronized"?

I thought in direction too, but I don't know if I can apply it. I'm starting three
threads. One feeds input to stdin; the two others capture output from stdout and
stderr. I shouldn't interfere or block anything until the child process has exited;
the threads should run inimpeded until then. Would you know how to introduce an
object here?
		Process process=Runtime.getRuntime().exec(execArgs);
		ProcessOutputStreamThread threadIn=
				new ProcessOutputStreamThread(
					process.getOutputStream(),pInputStream);
		ProcessInputStreamThread threadOut=
				new ProcessInputStreamThread(process.getInputStream());
		ProcessInputStreamThread threadErr=
				new ProcessInputStreamThread(process.getErrorStream());
		threadIn.start();
		threadOut.start();
		threadErr.start();
		mExitCode=process.waitFor();
		while (!threadOut.finished()) 
		{
			Thread.sleep(25);
		}
		while (!threadErr.finished()) 
		{
			Thread.sleep(25);
		}
		mProcOutput=threadOut.getOutput(); //String
		mProcErr=threadErr.getOutput(); //String


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /