且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从您自己的C#代码运行另一个应用程序?

更新时间:2023-10-21 11:12:22

好问题Mike.

这是您可以执行的操作:

Good question Mike.

This is how you can do this:

string inputPath = "\"\\\"C:\\some path\\filename.dat\\\"\"";
string outPutPath = "\"\\\"C:\\some path\\filename.out\\\"\"";


也许,只是注释:

1)您是否知道可以将控制台应用程序的输出重定向到任何流(不仅是文件,还可以是某些旨在读取和显示UI或类似结果的流)?请参见以下示例: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx [
Maybe, just side notes:

1) Do you know that you can re-direct output of the console application to any stream (not only the file, but, say, some stream designed to read and show results in UI or something like that)? See this sample: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx[^]. You can redirect both stdout and stderr, see System.Diagnostics.Process.StandardOutput, System.Diagnostics.Process.StandardInput, see also System.Diagnostics.Process.StandardInput.

2) If you use Process.WaitForExit() (you may or may not need it), you should understand this is blocking call, so you need to do it all in a separate thread. This is easy enough.

—SA