繁体   English   中英

通过C#对C程序的多个输入

[英]Multiple Inputs to a C Program through C#

我正在尝试将输入传递给通过Compiler通过C#编译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;
}

任何帮助/建议将不胜感激。

您是否尝试过使用Write而不是WriteLine

另外,如果可能,我建议更改C应用程序以将您的输入作为命令行参数,以便您可以直接从输入启动它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM