通过C#向C程序输入多个输入 [英] Multiple Inputs to a C Program through C#

查看:92
本文介绍了通过C#向C程序输入多个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力将输入传递给通过C#编译C编译程序生成的.exe文件。我的C#代码是:

  string  line =   1 +   2; 

流程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( 输入两个数字来添加\ n);
scanf( %d%d,& a,& b);

c = a + b;

printf( 输入数字的总和=%d \ n ,C);

return 0 ;
}





任何形式的帮助/建议都将受到赞赏。

解决方案

设置p.StartInfo.Arguments =行;



请参阅这里 [ ^ ](向下滚动机器人)示例。



AND:

在Main()中你没有说明:Main(字符串编号)并将其设置为所需的int。

I am working on passing inputs to an .exe file generated by compiling a C program by Compiler through C#. My C# code is:

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();


I successfully passed single inputs for C programs that read one input. But when i try to pass multiple inputs to C programs requiring multiple inputs, it only run exe file and it do not read/pass any of the inputs i provide. Also i have hidden the process of exe file but it opens it.

My C Code to which am trying to pass multiple inputs is:

#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;
}



Any kind of help / suggestion will be appreciated.

解决方案

Set the p.StartInfo.Arguments = line;

see here[^] (scroll a bot down) for the example.

AND:
In the Main() you do not state: Main(string numbers) and enset that to the desired int's.


这篇关于通过C#向C程序输入多个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆