gpt4 book ai didi

c# - Process.StartInfo.FileName 是否接受长文件名?

转载 作者:行者123 更新时间:2023-11-30 13:14:07 24 4
gpt4 key购买 nike

看起来不是。

如果我将文件名转换为其短值,则 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();

关于c# - Process.StartInfo.FileName 是否接受长文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/616898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com