如何使用System.Diagnostic从我的C#程序运行.exe并使用C#向EXE发送数据和从EXE获取数据

如何使用System.Diagnostic从我的C#程序运行.exe并使用C#向EXE发送数据和从EXE获取数据

问题描述:

我如何从我的C#程序运行 .exe应用程序和发送数据到.exe文件,.exe应用程序将处理我的数据,然后我接收从.exe处理的数据,然后我将使用System.Diagnostics在我的C#程序中显示此结果。?



实际上,我有Factorial.exe应用..我需要发送一个号码并从Factorial.exe获取结果,然后在我的C#程序中显示结果, 1000次,没有向用户显示Factorial.exe。



如果您能在C#中执行此操作,请提供一些代码或完整代码,



或资源将帮助我做到这一点以及我应该使用什么库和函数。



#RedirectStandardOutput #RedirectStandardInput



Moath

How can I run an .exe application from my C# program and send data to .exe file, the .exe application will make process to my data and then I Receive the data processed from .exe, then I will show this result in my C# program using System.Diagnostics.?

actually, I have Factorial.exe app.. and I need to send a number and get the result from Factorial.exe, and then show the result in my C# program,1000 times, without showing the Factorial.exe to the user.

Please provide me some Code or full code if you can in C# that do it,

or Resources that will help me to do it and what is the Library and Function should I use.

#RedirectStandardOutput #RedirectStandardInput

Moath

可能有很多其他方法可以完成这项任务,下面是你可以采用的一种方法试试这个:



1.创建命令接受参数作为数字的行exe然后你可以计算该输入的因子并返回结果。检查以下参考资料

http://www.dotnetperls.com/main [ ^ ]

http://msdn.microsoft.com/en-us/library/cb20e19t.aspx [ ^ ]

http://msdn.microsoft.com/en-us/library/aa288457(v=vs.71).aspx [ ^ ]



2.创建第二个应用程序并使用System.Diagnostics.Process和ProcessStartInfo,您可以通过提供参数执行以前的exe文件,并且您还可以读取StandardOutput作为结果的过程。检查

http: //msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput(v=vs.110).aspx [ ^ ]

http://stackoverflow.com/questions/4291912/process-start-how-to -get-the-output [ ^ ]
There may be many other ways to do this task, below is one way you can try this:

1. create command line exe which accept argument as number then you can calculate Factorial for that input and return the result. check below references
http://www.dotnetperls.com/main[^]
http://msdn.microsoft.com/en-us/library/cb20e19t.aspx[^]
http://msdn.microsoft.com/en-us/library/aa288457(v=vs.71).aspx[^]

2. Create 2nd application and using System.Diagnostics.Process and ProcessStartInfo you can execute previous exe file by providing argument and also you will able to read StandardOutput of the process as the result. check
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput(v=vs.110).aspx[^]
http://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output[^]