这是我的第一个问题,因此我将尽可能详细。我目前正在研究一个C#程序(我们将其称为TestProgram),该程序测试用C编写的另一个程序(我将其称为StringGen)。TestProgram应该在命令窗口中运行StringGen,然后将其输入一组输入字符串并记录每个输出的输出。运行StringGen时,它将启动while循环,等待输入,然后将该输入提交给处理函数,然后返回结果。
我的问题来自于当我尝试让TestProgram向StringGen提交字符串时。我正在将StringGen作为一个进程启动,并尝试使用Process.StandardInput.WriteLine()馈送输入,然后使用Process.StandardOutput.ReadLine()寻找输出。在进一步阐述之前,我将提供一些代码。
这是StringGen的主要功能:
int main() {
char result[255];
char input[255];
do {
fgets(input, 100, stdin);
result = GetDevices(input); //Returns the string required
printf("%s", result);
} while (input != "quit");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是我将StringGen定义为进程的C#代码:
Process cmd = new Process();
ProcessStartInfo info = new ProcessStartInfo(command, arguements); // Command is the path to the C executeable for StringGen
info.WorkingDirectory = workingDirectory; // Working Directory is the directory where Command is stored
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.UseShellExecute = false; …
Run Code Online (Sandbox Code Playgroud)