简体   繁体   中英

Executing .exe file with parameters in C#

I am automating some batch files into a single C# application but not having much luck. I have the following batch file (and another 3) that I am trying to write in C#

"C:\Program Files\IIS Express\iisexpress.exe" /path:c:\windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles /vpath:"/asp.netwebadminfiles" /port:61569 /clr:4.0 /ntlm

Here is the C# code I have found online but it fails:

using (Process proc = new Process())
{
    proc.StartInfo.FileName = "iisexpress.exe";
    proc.StartInfo.Arguments = @"/path:c:\windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles /vpath:/asp.netwebadminfiles /port:61569 /clr:4.0 /ntlm";
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.RedirectStandardOutput = true;
    proc.Start();
    proc.WaitForExit();
    Console.Out.WriteLine(proc.StandardOutput.ReadToEnd());
}

I get the following, with no help from Google:

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll

您需要为Process.StartInfo.FileName提供exe的完整路径:

proc.StartInfo.FileName = @"C:\Program Files\IIS Express\iisexpress.exe";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM