【发布时间】:2015-02-20 07:24:39
【问题描述】:
我正在尝试将文件路径作为命令行参数传递。如果没有空格的路径可以正常工作,但如果有空格则不行。在下面的代码中,commandText“scriptPath”甚至可以使用空格。 但是变量“file1”和“file2”不能使用空格。
string scriptFilePath = "@" + string.Format("\"{0}\"", "D:\\Script\\ScriptFile.txt");
string file1 = @"D:\New Folder\file1.png";
string file2 = @"D:\New Folder\file2.png";
string outPutPath = @"D:\New Folder\Output\Report.html";
string commandText = "/c " + "BCompare.exe" + scriptFilePath + " " + file1 + " " + file2 + " " + outPutPath;
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WorkingDirectory = @exePath;
startInfo.FileName = "cmd.exe";
startInfo.RedirectStandardInput = true;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
startInfo.Arguments = commandText;
proc = Process.Start(startInfo);
proc.WaitForExit();
【问题讨论】:
-
格式化你的问题,这是不可读的!
-
嗨,Nathan Tuggy,这里的要求是我必须在 BCompare.exe 中运行一个脚本文件(比较两个图像文件)。因此,我通过命令提示符在 BCompare.exe 中运行脚本。为了更好地理解,我在上面编辑了我的代码。我要在命令提示符下执行的命令是 BCompare.exe @D:\Script\ScriptFile.txt D:\New Folder\file1.PNG D:\New Folder\file2.PNG D:\New Folder\Output\Report。 html。这里,file1 & file2 是传递给 scriptFile.txt 的参数,它将在指定的路径中生成 Report.html。
-
我很想将此标记为 stackoverflow.com/questions/15061854/… 的副本。
标签: c#