我正在努力添加中继功能,以在我的多功能工具中具有另一种语言(控制台应用程序)的另一种工具的功能,并使其自动化。但是我无法从中读取输出,因为它似乎为空(很明显,我的标签设置知道它是否找到了任何东西)。
我知道重定向输入工作正常。
尝试使用Timer(我目前正在使用的是什么),没有任何输出。 使用Direct方法进行错误和输出尝试,使构建器工具和我的工具均崩溃。 (代码略有不同。) 尝试直接插入行而不接触输出,效果很好,但是如果发生任何异常情况(例如生成器缺少文件),则不可靠。
我花了多个小时来查找解决此问题的方法,类似的问题,但没有任何效果。
开始流程:
pr = new Process();
pr.StartInfo = new ProcessStartInfo()
{
FileName = @"C:\PoppyTemp\TheOFWModdingTool\Tools\PKG Builder/repacker.exe",
WorkingDirectory = @"C:\PoppyTemp\TheOFWModdingTool\Tools\PKG Builder\"
};
pr.EnableRaisingEvents = true;
pr.Exited += new EventHandler(cmd_Exited2);
pr.OutputDataReceived += new DataReceivedEventHandler(CheckAndDisableResigningThenBuild);
pr.ErrorDataReceived += new DataReceivedEventHandler(CheckAndDisableResigningThenBuild);
pr.StartInfo.RedirectStandardInput = true;
pr.StartInfo.RedirectStandardOutput = true;
pr.StartInfo.RedirectStandardError = true;
pr.StartInfo.UseShellExecute = false;
pr.StartInfo.CreateNoWindow = false;
bool processStarted = pr.Start();
if (processStarted)
{
//pr.BeginOutputReadLine();
//pr.BeginErrorReadLine();
LeTimer.Interval = 1200;
LeTimer.Enabled = true;
LeTimer.Tick += new EventHandler(CheckAndDisableResigningThenBuild);
LeTimer.Start();
//Not Useful In My Case
//pr.WaitForExit();
}
计时器正在调用什么:
StreamWriter SendToBuilder = pr.StandardInput;
StreamReader ReadFromBuilderOutput = pr.StandardOutput;
StreamReader ReadFromBuilderError = pr.StandardError;
//Thread.Sleep(500);
//SendToBuilder.WriteLine("R");
//Thread.Sleep(500);
//SendToBuilder.WriteLine("Y");
//Thread.Sleep(500);
//SendToBuilder.WriteLine("Y");
//Thread.Sleep(500);
//SendToBuilder.WriteLine("1");
//Thread.Sleep(500);
//SendToBuilder.WriteLine("1");
//Thread.Sleep(15000)
string OutputText = null;
OutputText += ReadFromBuilderOutput.ReadToEnd();
OutputText += ReadFromBuilderError.ReadToEnd();
if (OutputText.Contains("Resign EBOOT.BIN: [ON]"))
{
if (OutputText.Contains("Enter Y to disable Resign Eboot / any other key to abort"))
{
label11.Text = "Confirming Turn Off For Resigning..";
label11.Refresh();
SendToBuilder.WriteLine("y");
Thread.Sleep(500);
SendToBuilder.WriteLine("y");
}
else
{
label11.Text = "Resign Is On, Turning Off..";
label11.Refresh();
SendToBuilder.WriteLine("r");
}
}
if (OutputText.Contains("Resign EBOOT.BIN: [OFF]"))
{
label11.Text = "Resign Is Off, Opening Fast Pack..";
label11.Refresh();
SendToBuilder.WriteLine("1");
Thread.Sleep(500);
SendToBuilder.WriteLine("1");
}
else if (OutputText.Contains("Packing Pkg is finished."))
{
label11.Text = "Build Finished!";
if (OutputText.Contains("Press any key to continue..."))
{
label11.Text = "Build Finished! Closing Builder..";
label11.Refresh();
LeTimer.Stop();
SendToBuilder.WriteLine("1");
pr.Close();
pr.Kill();
}
}
我期望输出并希望能够阅读:
===============================================================================
| TrueAncestor PKG Repacker |
| by JjKkYu |
| Verision 2.45 |
===============================================================================
| OPERATION | STATUS |
===============================================================================
| 1. Fast Pack Pkg | 6. Show Game Folder Info |
| 2. Custom Pack Pkg | 7. Edit PARAM.SFO |
| 3. Unpack Pkg | 8. Show Pkg Info |
| 4. Repack Pkg | |
| 5. Finalize Pkg | |
===============================================================================
| SWITCH | INFORMATION |
===============================================================================
| P. Patch PARAM.SFO: [ON] | C. Credits |
| R. Resign EBOOT.BIN: [ON] | I. Instructions |
| U. Unpack Engine: [ungpkg] | G. Get Series Tools |
| | T. About TrueAncestor |
===============================================================================
| Note: Place Pkg files into pkg folder before starting process. |
| Place Game Content folders into game folder before starting process. |
| Place Edat files into edat folder before starting process. |
| Place Theme files into theme folder before starting process. |
| Place Avatar files into avatar folder before starting process. |
| Place Rap files into raps folder before starting process. |
===============================================================================
[?] Please enter your choice (1-8/P/R/U/C/I/G/T):
我认为我期望的结果应该显而易见。我希望它能够找到我指定的在工作时出现在工具中的任何文本,这意味着我可以使用它来知道它何时运行,出现错误或正在等待/滞后(某些PC并非非常好,这意味着会有延误,这是一个与地雷有关的公开发布的地雷计划)。
编辑:尽管在ReadFromBuilderOutput.ReadToEnd()之后,输出仍可以正常工作完成后,我无法将“当前位置”返回到构建器程序的起始行,这意味着它仅适用于一次读取。可以解决吗? -本质上,我需要不断地从输入流中读取输出变化的输出,现在我只进入“ Resign Is On,Turning Off ..”阶段,并停留在那里。
编辑2:更新了我正在使用的代码示例。
我只能提取一次的输出的屏幕截图:https://imgur.com/a/uXey1Pc
很抱歉,我的第二篇帖子被弄乱了。