看起来不是.
如果我将文件名转换为其短值,则Process.Start()可以正常工作.
Process runScripts = new Process(); runScripts.StartInfo.FileName = @"C:\long file path\run.cmd"; runScripts.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; runScripts.StartInfo.UseShellExecute = true; runScripts.StartInfo.RedirectStandardOutput = false; runScripts.Start();
上面的代码失败了.但...
Process runScripts = new Process(); runScripts.StartInfo.FileName = @"C:\short\file\path\run.cmd"; runScripts.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; runScripts.StartInfo.UseShellExecute = true; runScripts.StartInfo.RedirectStandardOutput = false; runScripts.Start();
成功.
我设法通过将长路径名称转换为短路径名称来解决这个问题.但我发现这一点有点惊讶.有关于此的任何原因或背景信息?
谢谢.
更新1
Microsoft .NET Framework版本2.0.50727
这很好奇,我重现了这个行为,实际上,它没有像你说的那样执行,但修改它,它起作用了:
System.Diagnostics.Process runScripts = new System.Diagnostics.Process(); runScripts.StartInfo.FileName = @"run.cmd"; // new runScripts.StartInfo.WorkingDirectory = @"C:\long file path"; runScripts.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; runScripts.StartInfo.UseShellExecute = true; runScripts.StartInfo.RedirectStandardOutput = false; runScripts.Start();