I'm using a C# Process to run the following Java code with the java
command:
public class Test {
public static void main(String[] args) throws Exception {
Thread.sleep(2000);
System.out.print("Hello worl\nd 1!");
Thread.sleep(2000);
System.out.println("Hello world 2!");
}
}
I'm using the following code to listen to the output:
run.OutputDataReceived += (_, args) => { /* handle output */ };
run.Start();
run.BeginOutputReadLine();
Ideally, OutputDataReceived
should be fired twice, with the coressponding values for args.Data
:
"Hello worl\nd 1!"
"Hello world 2!\n"
Instead, the newlines are used to determine when OutputDataReceived
is fired. This ends up giving 3 calls to the event, with the corresponding values to args.Data
:
"Hello worl"
"d 1!Hello world 2!"
null
How would I run code to handle output according to my first scenario (each time stdout is updated) instead of what is currently happening/the second scenario (whenever stdout receives a new line)? In addition, how would I do the same for stderr as well?