没有重定向StdOut的Processbuilder [英] Processbuilder without redirecting StdOut

查看:107
本文介绍了没有重定向StdOut的Processbuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将输出流重定向回流程,或者根本不重定向?

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

背景故事:
我正试图启动使用processbuilder的可执行文件。
(确切地说是源专用服务器/ srcds.exe)

The backstory: I am trying to launch an executable using processbuilder. (Source dedicated server / srcds.exe to be exact)

作为使用processbuilder启动它的结果,此可执行文件的控制台窗口保持为空。启动后几秒钟,可执行文件崩溃时出现错误CTextConsoleWin32 :: GetLine:!GetNumberOfConsoleInputEvents,因为它的控制台是空的。

As a result of launching it with the processbuilder, the console window of this executable remains empty. A few seconds after launch, the executable crashes with the error "CTextConsoleWin32::GetLine: !GetNumberOfConsoleInputEvents" because its console is empty.

推荐答案

我认为你在谈论让已启动的进程'stdout转到当前进程'stdout。如果您使用的是JDK7,那就简单如下:

I think you're talking about making the launched process' stdout go to the current process' stdout. If you're using JDK7, that's as simple as:

.redirectOutput(ProcessBuilder.Redirect.INHERIT)

更新:(评论太多了)我觉得你很困惑。当您从终端启动进程时,该进程将成为该终端进程的子进程,并且该stdout将发送到该终端。当您从Java启动进程时,该进程是Java进程的子进程,其stdout进入Java。

Update: (too much for a comment) I think you're confused. When you launch a process from a terminal, the process becomes a child of that terminal process, and the stdout is sent to that terminal. When you launch a process from Java, then the process is a child of the Java process, and its stdout goes to Java.

在第一种情况下,有一个终端显示stdout因为你自己从终端发起它,这就是终端用stdout做的事情。但是,当从Java启动时,除非您启动的进程中的某些东西打开了终端,否则将没有终端窗口,并且您启动的进程的stdout将交给您,即程序员,您可以随意使用。与从终端启动时看到的相同的行为是我已经提到的 Redirect.INHERIT

In the first case, there's a terminal showing stdout because you launched it from a terminal yourself, and that's what terminals do with stdout. When launching from Java, however, there wouldn't be a terminal window unless something in the process you launched opened a terminal, and stdout of the process you launched is handed back to you, the programmer, to do with as you will. The equivalent behavior to what you see when launching from a terminal is the Redirect.INHERIT that I already mentioned.

你现在的问题不是Java。您的问题是不了解这个srcds.exe如何处理stdin和stdout。想出来,然后再回来询问如何用Java做到这一点。

Your problem right now isn't Java. Your problem is not understanding how this "srcds.exe" expects stdin and stdout to be handled. Figure that out, and then come back and ask how to do that with Java.

我现在只是猜测,但你可以尝试从过程'stdout中读取把它喂回斯坦丁。也许这就是它所期待的?但这听起来很疯狂。

I'm just guessing now, but you could try reading from the process' stdout and feeding it back into the stdin. Maybe that's what it's expecting? That sounds crazy, though.

这篇关于没有重定向StdOut的Processbuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆