通过C#对C程序进行多个输入
Multiple Inputs to a C Program through C#
我正在将输入传递到一个.exe文件,该文件是由编译器通过C#编译C程序生成的。我的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 addn");
scanf("%d%d",&a,&b);
c = a + b;
printf("Sum of entered numbers = %dn",c);
return 0;
}
任何形式的帮助/建议都将不胜感激。
您是否尝试过使用Write
而不是WriteLine
?
此外,如果可能的话,我建议更改C应用程序,将您的输入作为命令行参数,这样您就可以直接使用输入启动它。
相关文章:
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 无法在windows控制台中为C++程序提供必要的输入
- 更改.cpp程序的输入文件中数据的位置会意外更改输出
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 我的程序没有从文件中读取并输入数据
- 3-3. 编写一个程序来计算每个不同单词在其输入中出现的次数
- 为什么有时我输入一个整数,程序将第一个输入的数字打印成十进制数?
- LLVM | codegen 用于带有命令行选项的程序输入功能
- 为什么当我输入较大的数字时,我的程序会到达文件末尾?
- 编写一个不断要求用户输入的程序
- 程序中的布尔函数返回输入的范围无论如何都是无效的
- 为什么我的程序在输入某个形状的面积的测量值后没有结束?
- 在这个无限循环中,当输入 0 时终止,当输入 int 范围之外的任何内容时,程序行为不正常
- 一个C++程序,用于在输入位数时输出具有特定位数的 .txt 文件中的所有数字
- 如何将输入C 程序的平均值输入
- Sudoku输入程序跳过提示
- 无法将文件输入 C++ 程序
- 简单的c++输入程序
- 简单输入程序崩溃
- 用户用于输入程序设置的文件约定