Processbuilder without redirecting StdOut

Is it possible to redirect the output stream back to the process or not redirect it at all?

Background: I am trying to run an executable using processbuilder. (The original dedicated server /srcds.exe, to be precise)

As a result of running it using processbuilder, the console window of this executable file remains empty. A few seconds after starting the executable file fails with the error "CTextConsoleWin32 :: GetLine :! GetNumberOfConsoleInputEvents", because the remote is empty.

+4
source share
2 answers

I think you are talking about starting a standard run of stdout on the current process. If you are using JDK7, it is simple:

.redirectOutput(ProcessBuilder.Redirect.INHERIT) 

Update: (too much for comment) I think you are confused. When you start a process from a terminal, the process becomes a child of this terminal process, and stdout is sent to this terminal. When you start a process from Java, this process is a child of the Java process, and its stdout switches to Java.

In the first case, there is a terminal showing stdout, because you started it from the terminal yourself and that you use stdout with the terminals. However, when starting from Java, there would not be a window if only something in the process that you started did not open the terminal, and the beginning of the process that you started is transferred to you, the programmer, at your discretion. The equivalent behavior that you see when starting from the terminal is Redirect.INHERIT , which I already mentioned.

Your problem right now is not in Java. Your problem is not understanding how this "srcds.exe" expects stdin and stdout to be processed. Extract this and then go back and ask how to do it with Java.

I guess right now, but you can try reading from the stdout process and returning it back to stdin. Maybe this is what he expects? That sounds crazy, however.

+4
source

you can get the result as follows

 ProcessBuilder pb = new ProcessBuilder(args); Process p = pb.start(); //below code gets the output from the process InputStream in = p.getInputStream(); BufferedInputStream buf = new BufferedInputStream(in); InputStreamReader inread = new InputStreamReader(buf); BufferedReader bufferedreader = new BufferedReader(inread); String line; while ((line = bufferedreader.readLine()) != null) { *do something / collect output* } 
0
source

Source: https://habr.com/ru/post/1414782/


All Articles