0

I am trying to pass file path as command line argument. If the path without spaces it works fine, but with spaces it is not. In below code commandText "scriptPath" is working even with spaces. But the variables "file1" & "file2" are not working with spaces.

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();
Ash K
  • 1,802
  • 17
  • 44
krish
  • 21
  • 1
  • 3
  • format your question, this is unreadable ! – mybirthname Dec 22 '14 at 07:48
  • Hi, Nathan Tuggy, Here the requirement is I have to run a script file (to compare two image files) in BCompare.exe. So, am running the script in BCompare.exe through command prompt. For better understanding I have edited my code above. My command to be executed in command prompt is, BCompare.exe @D:\Script\ScriptFile.txt D:\New Folder\file1.PNG D:\New Folder\file2.PNG D:\New Folder\Output\Report.html. Here, file1 & file2 are arguements passed to the scriptFile.txt, which will generate Report.html in the path specified. – krish Dec 23 '14 at 07:41
  • I'm tempted to flag this as a duplicate of http://stackoverflow.com/questions/15061854/how-to-pass-multiples-arguments-in-processstartinfo . – BCdotWEB Dec 23 '14 at 08:30

3 Answers3

1

Put your file paths in quotation marks.

Rainer
  • 326
  • 2
  • 14
1

Solution 1

string file1 = @"D:\New Folder\file1.png";

Solution 2

string file2 = "\"D:\\New Folder\\file2.png\"";
LPs
  • 16,045
  • 8
  • 30
  • 61
  • Hi, Thank you for you reply. The file names are enclosed with quotes already. And I tried prefixing file path with @ symbol. This doesnt work. Solution 1 & 2: tried, doesnt work – krish Dec 23 '14 at 05:38
  • Sorry, but I was from the android app that doesn't allow (or I'm not able to) to format code. I corrected solution 2: try it! – LPs Dec 23 '14 at 08:13
0

Please fix your code first:

  • Missing semicolons
  • Fix paths in code and make them readable (use String.Format and use @)
  • I think you want to execute "executable.exe" with the command lines, so use "executable.exe" as startInfo.FileName and just add the remaining arguments (scriptPath, file1, file2) to the startInfo.Arguments and make sure that all of them are between double quotes
Roemer
  • 2,012
  • 1
  • 24
  • 26