从c#发送具有空格的路径到批处理文件

时间:2014-11-08 10:17:36

标签: c# windows visual-studio batch-file

我有一个应用程序从应用程序中执行批处理文件。批处理文件包含此

attrib %1 +h +r +s /s /d
pause

我在c#应用程序中的代码是

Process p = new Process();
string m=@"C:\Users\INDERJEET\Desktop\Antivirus works\Antivirus\Batchfiles\Testproject";
p.StartInfo.FileName = @"C:\Users\INDERJEET\Desktop\Antivirus works\Antivirus\Batchfiles\hide_2.bat";
p.StartInfo.Arguments = m;
p.StartInfo.Verb = "runas";
p.Start();

什么时候我跑这个。它似乎只挑选路径uptil C:\ Users \ INDERJEET \ Desktop \ Antivirus而不是之后..如何将整个路径发送到cmd。

1 个答案:

答案 0 :(得分:1)

尝试在路径周围使用双引号(")。由于您正在使用字符串文字,因此您需要使用第二个双引号(例如此"")来转义双引号:

string m = @"""C:\Users\INDERJEET\Desktop\Antivirus works\Antivirus\Batchfiles\Testproject""";

上述代码的结果应将以下参数传递到批处理文件中:

"C:\Users\INDERJEET\Desktop\Antivirus works\Antivirus\Batchfiles\Testproject"
相关问题