Reputation: 85
I am trying to create a Visual Studio Add-In by using Visual Studio 2015, VSIX project. The add-in should be able to run an .exe file along with current project path. Currently i can find the path of the project and give it as argument of the Process (the .exe file). The .exe file is run by cmd as follows:
the.exe -d projectDirectoryPath
Detecting the project path is not my problem but, if the path contains Space Character , it is understood as a seperate argument. Following code is what i've used for starting the process:
string myDir = activeProjectPath();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.FileName = pathOfExe + "\\the.exe";
startInfo.Arguments = "-d " + myDir;
The code works fine when the path of the current project does not contain Space Character, otherwise process can not started. The process gives following error:
Given args:-d C:\Users\theUser\Documents\Visual Studio 2015\Projects\testProject\testProject
Too many arguments specified in your command line! Skipping extra argument: Studio
Too many arguments specified in your command line! Skipping extra argument: 2015\Projects\testProject\testProject
Note: When i try to run the.exe from cmd, it accepts space characters in the path of the projects.
How can i solve this issue?
Thanks!
Upvotes: 1
Views: 1643
Reputation: 1927
Try to use " character. You can specify the path in the following form: "C:\Users\foo\My Documents\file name.sln", for example. You can surround any path with " character, like in batch or Powershell script.
startInfo.Arguments = string.Concat("-d ", "\"", myDir, "\"");
Upvotes: 2