我曾尝试过此代码,但不确定这是否正确。 .exe文件(部分)打开但未执行操作。
请帮帮我。
代码:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardError = true;
startInfo.WorkingDirectory = @"C:\\Program Files\\SQL Sentry\\SQL Sentry Plan Explorer";
startInfo.FileName = @"C:\\Program Files\\SQL Sentry\\SQL Sentry Plan Explorer\\SQL Sentry Plan Explorer.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = @"C:\\Program Files\\SQL Sentry\\SQL Sentry Plan Explorer\\XMLFile1.xml";
System.Threading.Thread.Sleep(1000);
try
{
using (Process p = Process.Start(startInfo))
{
p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
}
catch (Exception e17)
{
MessageBox.Show("17");
MessageBox.Show(e17.ToString());
}
答案 0 :(得分:1)
从字符串中删除双斜杠并在参数
处放置单引号 startInfo.WorkingDirectory = @"C:\Program Files\SQL Sentry\SQL Sentry Plan Explorer";
startInfo.FileName = @"C:\Program Files\SQL Sentry\SQL Sentry Plan Explorer\SQL Sentry Plan Explorer.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = @"'C:\Program Files\SQL Sentry\SQL Sentry Plan Explorer\XMLFile1.xml'";
答案 1 :(得分:0)
尝试用单引号包装文件(参数)的路径:
startInfo.Arguments = @"'C:\\Program Files\\SQL Sentry\\SQL Sentry Plan Explorer\\XMLFile1.xml'";
您始终可以尝试从命令行手动运行exe以确认它是否按预期工作。
答案 2 :(得分:0)
只需使用,
System.Diagnostics.Process.Start(@"C:\Windows\system32\notepad.exe", "[arguments]");
更多@ Process