【发布时间】:2014-08-28 07:27:54
【问题描述】:
我正在将输入传递给通过 C# 由 Compiler 编译 C 程序生成的 .exe 文件。我的 C# 代码是:
string line = "1" + " 2 " ;
Process p = new Process();
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.FileName = "C:\\..\\demo1.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.Start();
p.StandardInput.WriteLine(line);
p.Close();
我成功地为读取一个输入的 C 程序传递了单个输入。但是当我尝试将多个输入传递给需要多个输入的 C 程序时,它只运行 exe 文件并且它不读取/传递我提供的任何输入。我也隐藏了exe文件的进程,但它会打开它。
我尝试向其传递多个输入的 C 代码是:
#include<stdio.h>
int main()
{
int a, b, c;
printf("Enter two numbers to add\n");
scanf("%d%d",&a,&b);
c = a + b;
printf("Sum of entered numbers = %d\n",c);
return 0;
}
我们将不胜感激任何形式的帮助/建议。
【问题讨论】: