0

I've got some c# code that launches a java process. On one machine running Windows 7 it works fine. On another running XP it doesn't. Here is the code...

mServerProcess = new Process(); mServerProcess.StartInfo.FileName = "java"; mServerProcess.StartInfo.Arguments = "-jar my.jar"; mServerProcess.StartInfo.WorkingDirectory = "C:\\my_server"; mServerProcess.StartInfo.UseShellExecute = false; mServerProcess.StartInfo.CreateNoWindow = true; mServerProcess.StartInfo.RedirectStandardOutput = true; mServerProcess.StartInfo.RedirectStandardError = true; mServerProcess.StartInfo.RedirectStandardInput = true; mServerProcess.OutputDataReceived += new DataReceivedEventHandler(ServerOutputHandler); mServerProcess.ErrorDataReceived += new DataReceivedEventHandler(ServerErrorHandler); mServerProcess.SynchronizingObject = this.console; // Start the process. mServerProcess.Start(); // Start the asynchronous read of the sort output stream. mServerProcess.BeginOutputReadLine(); mServerProcess.BeginErrorReadLine(); 

On the XP machine I never get the text coming from the process's standard error, and the process in general seems broken. I can't send it anything from the standard input stream.

Now... interestingly, if I comment out the code that redirects standard input, I DO get the standard error. But of course, I NEED to redirect standard input as well.

Has anyone seen this before?... where redirecting both standard input and standard error cause a problem?

And again... I don't have this problem on my windows 7 box.

Thanks, Buzz

UPDATE:

I'm using the java Logger class to output information from my java app. I think this problem is related to Java specifically and how its ConsoleHandler class deals with standard error. This is driving me nuts!

3 Answers 3

1

The process is probably waiting for some input.

Try giving it some input.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 - yup - "if I comment out the code that redirects standard input ..." is a dead give-away :-)
0

If you redirect both input and output you can potentially deadlock the I/O. Depending on the buffering this could behave differently on different operating systems or with different inputs and outputs. For example, it might appear to work fine when with 1k of input but hang with 4k. See the documentation and search for deadlock:

1 Comment

I've been all over that page. I can't see anything wrong with my method. I am not using any of the blocking read calls on the streams. I am using the asynchronous calls.
0

Are you invoking a Java process that uses Jline? If so then you need to invoke it with the following parameter:

-Djline.terminal=jline.UnsupportedTerminal 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.