[英]What's the big deal with ProcessStartInfo.UseShellExecute?
[英]ProcessStartInfo and UseShellExecute usage
我正在使用以下代碼在ac#應用程序中執行shell命令:
try
{
Process prc = new Process();
prc.StartInfo = new ProcessStartInfo();
prc.StartInfo.FileName = filename;
prc.StartInfo.Arguments = arg;
prc.StartInfo.UseShellExecute = false;
prc.StartInfo.RedirectStandardOutput = true;
prc.Start();
prc.StandardOutput.BaseStream.CopyTo(stream);
prc.WaitForExit();
} catch (Exception e){
Console.WriteLine("{0} Exception caught.", e);
}
如果我輸入“ ipconfig”或“ whoami”之類的命令,它將起作用。 但是當我輸入例如“ dir”時,我得到:
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
知道為什么嗎? 這有什么竅門?
由於dir是cmd.exe中的命令,因此無法自行啟動它,但可以像這樣執行它。
System.Diagnostics.Process.Start("CMD.exe","dir");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.