[英]No output when trying to redirect standard and/or error. How can i read the output from this?
When i try to redirect output from a executable running in batch mode there are only a few lines that shows up and there are no more output. 当我尝试从以批处理模式运行的可执行文件重定向输出时,只有几行显示,并且没有更多输出。 Although i have set the window to not be visible it pops up anyway, but there are no output in the window so clearly the output are redirected but not showing.
虽然我已将窗口设置为不可见,但无论如何都会弹出该窗口,但是窗口中没有输出,因此输出显然已重定向但未显示。
The executable is normally started like this: RustDedicated.exe -batchmode +more +arguments +here
可执行文件通常是这样启动的:
RustDedicated.exe -batchmode +more +arguments +here
Now, when i try to spawn the exe file within my C# application only the very first lines outputs in debug console, the actual application window does not output anything. 现在,当我尝试在C#应用程序中生成exe文件时,调试控制台中仅输出第一行,实际的应用程序窗口将不输出任何内容。
Here are some code: 这是一些代码:
Process serverProcess;
private void StartServerThread()
{
var serverArguments = GenerateServerArguments();
var serverExecutable = Properties.Settings.Default.Rustserverexecutable;
try
{
ProcessStartInfo info = new ProcessStartInfo
{
WorkingDirectory = System.IO.Path.GetDirectoryName(serverExecutable),
FileName = serverExecutable,
Arguments = "-batchmode",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
//WindowStyle = ProcessWindowStyle.Hidden //Application window show no mather what.
};
serverProcess = new Process();
serverProcess.StartInfo = info;
serverProcess.OutputDataReceived += ServerProcess_OutputDataReceived;
serverProcess.ErrorDataReceived += ServerProcess_ErrorDataReceived;
serverProcess.Start();
serverProcess.BeginOutputReadLine();
serverProcess.BeginErrorReadLine();
//serverProcess.StandardInput.WriteLine(serverExecutable + serverArguments); // I tested with cmd.exe and feeding it the path to the executable with arguments, same result.
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
}
Also, as i have commented in the code i have tried to start CMD in interactive mode /K
and the feeding it the path to the executable, and i have tried to redirect from a batch file wich does the same. 另外,正如我在代码中所做的评论一样,我尝试以交互方式
/K
启动CMD并将其提供给可执行文件的路径,并且尝试从批处理文件中重定向(至此)。 Same result. 结果相同。
I have tried both ErrorData and OutputData. 我已经尝试了ErrorData和OutputData。
Here are the code for that: 这是代码:
private void ServerProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
if (!string.IsNullOrEmpty(e.Data.ToString()))
{
Application.Current.Dispatcher.BeginInvoke(new Action(() => {
txt_ServerMessage.Document.Blocks.Add(new Paragraph(new Run("ErrorData: "+e.Data.ToString())));
}));
}
}
private void ServerProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
if (!string.IsNullOrEmpty(e.Data.ToString()))
{
Application.Current.Dispatcher.BeginInvoke(new Action(() => {
txt_ServerMessage.Document.Blocks.Add(new Paragraph(new Run(e.Data.ToString())));
}));
}
}
The Game server is working, but no output to work with. 游戏服务器正在运行,但是没有可用的输出。
What can be the reason of this? 这可能是什么原因? How can i successfully redirect the output?
我如何成功重定向输出?
it's still actual for me. 对我来说仍然是现实。 Also work on automation work with Rust server, RustDedicated.exe.
也可以使用Rust服务器RustDedicated.exe进行自动化工作。 So I ended up with usage of RestDedicated.exe -logfile output.txt, and watching it.
因此,我最终使用了RestDedicated.exe -logfile output.txt,并进行了观察。
node.js TS example: node.js TS示例:
let pipe_file = 'output.txt';
const server_process = spawn('RustDedicated.exe', ['-batchmode', '-logfile', pipe_file],
{
windowsHide: false,
cwd: path.dirname(server_exe),
shell: true,
detached: true,
});
const pipe_full_path: string = path.join(path.dirname(server_exe), pipe_file);
let tail = new Tail(pipe_full_path);
fs.watchFile(pipe_full_path, (cur, prev) => {
console.log(prev.mtime, cur.mtime);
});
tail.on("line", (data) => {
console.log(data);
});
tail.on("error", (error) => {
console.log('ERROR: ', error);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.