【发布时间】:2013-10-25 15:11:07
【问题描述】:
我尝试使用以下代码从 c# 运行批处理文件,我想在 WPF 文本框中显示结果。你能指导我怎么做吗?
using System;
namespace Learn
{
class cmdShell
{
[STAThread] // Lets main know that multiple threads are involved.
static void Main(string[] args)
{
System.Diagnostics.Process proc; // Declare New Process
proc = System.Diagnostics.Process.Start("C:\\listfiles.bat"); // run test.bat from command line.
proc.WaitForExit(); // Waits for the process to end.
}
}
}
此批处理文件用于列出文件夹中的文件。批处理执行后,结果应显示在文本框中。如果批处理文件有多个命令,则每个命令的结果都应显示在文本框中。
【问题讨论】:
-
结果来自不同的文件因此不同的进程,您可以使用 Pipe(或 WCF)访问您的应用程序,您将无法找出这些结果
标签: c# wpf batch-file process command-line-arguments