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(); 
3
  • format your question, this is unreadable ! Commented Dec 22, 2014 at 7: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. Commented Dec 23, 2014 at 7:41
  • I'm tempted to flag this as a duplicate of stackoverflow.com/questions/15061854/… . Commented Dec 23, 2014 at 8:30

3 Answers 3

2

Put your file paths in quotation marks.

Sign up to request clarification or add additional context in comments.

Comments

1

Solution 1

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

Solution 2

string file2 = "\"D:\\New Folder\\file2.png\""; 

2 Comments

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
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!
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.