C# Process.StartInfo.FileName,带撇号
我希望这是一个简单的问题。以下是我正在做的:C# Process.StartInfo.FileName,带撇号,c#,.net,mono,C#,.net,Mono,我希望这是一个简单的问题。以下是我正在做的: Process process = new Process { StartInfo = { FileName = "C:\\David's Program\\program.exe", CreateNoWindow = true, RedirectStandardOutput = true, UseShellExecute = false } }; process.Sta
Process process = new Process {
StartInfo = {
FileName = "C:\\David's Program\\program.exe",
CreateNoWindow = true,
RedirectStandardOutput = true,
UseShellExecute = false
}
};
process.Start();
问题是文件名
有一个撇号,这会导致:
Win32Exception: ApplicationName='C:\David's Program\program.exe'…
我已经用FileName
在C:\\Davids Program\\Program.exe
(没有撇号)测试了这段代码,没有例外。另外,在使用带有撇号的文件名时设置UseShellExecute=true
(并且不尝试重定向标准输出)也可以正常工作
因此UseShellExecute=false
和文件名中的撇号肯定是罪魁祸首。但是,为了我的生命,我不知道如何逃避它。我试过\'
,\\'
,\\\\'
和\\\\\'
都没用
有什么想法吗?谢谢
编辑:我在Mono 2.6(近似.NET 2.6奇偶校验)环境中工作
编辑2:产生相同异常的其他尝试:
“\”C:\\David's Program\\Program.exe\”
@“C:\David's Program\Program.exe”
String.Format(“C:\\David{0}s Program\\Program.exe”,(char)39)
我还在不同的位置使用不同的.exe进行了测试,在每个测试实例中,我都重命名了包含的目录以删除撇号,结果发现代码运行正常。您是否尝试过FileName=“\”C:/David's Program/Program.exe“”
?我猜您只需要将文件名用双引号括起来,如filename=“\“C:\\David's Program\\Program.exe\”
Process Process=new Process{StartInfo={filename=@“C:\Test's\Test.bat”,//CreateNoWindow=true,//RedirectStandardOutput=true,UseShellExecute=false};process.Start();//没问题,而且exception@Ren遗憾的是,这不是答案。同样的例外情况。String.Format(“C:\\David{0}s Program\\Program.exe”,(char)39)
怎么样?