我不能得到這個返回任何東西,我期待在當前目錄中的文件列表,但它什麼都沒有返回。c#執行命令行並返回字符串
class Program
{
static void Main(string[] args)
{
PublishProject();
Console.ReadLine();
}
public static void PublishProject()
{
//Create process
var pProcess = new System.Diagnostics.Process
{
StartInfo =
{
FileName = "cmd.exe",
Arguments = "dir",
UseShellExecute = false,
RedirectStandardOutput = true,
WorkingDirectory = "C:\\"
}
};
pProcess.Start();
Console.Write(pProcess.StandardOutput.ReadToEnd());
pProcess.Close();
Console.WriteLine("done");
}
}
是否有你不使用System.IO類的原因? – 2012-02-16 02:53:03