Reputation: 33
I am getting a string variable for the Application.ExecutablePath and then passing the variable to a command line via ProcessStartInfo with some arguments. My code works fine as long as the "ExecutablePath" does not contain spaces, but if it does such as C:\documents and settings\jsmith\desktop, C# processes the spaces as escapes and I don't get results from the command line.
Here is how I am getting the Path and also sending the command "lmutil"
string execName = Application.ExecutablePath;
FileInfo execFileInfo = new FileInfo(execName);
execPath = execFileInfo.DirectoryName;
string lmUtil = @"\lmutil";
lmExec = execPath + lmUtil;
This is the method in which I need to handle quotes in paths
GetLicStats(lmExec + " lmstat -a -c " + licport + "@" + curAdd);
How can I make sure that lmExec is handled correctly if it contains spaces.
Upvotes: 1
Views: 341
Reputation: 4780
GetLicStats(lmExec + " lmstat -a -c " + licport + "@\"" + curAdd + "\"");
Put quotes around the address usually works
Upvotes: 3
Reputation: 55344
execPath = execFileInfo.DirectoryName.Replace(" ", "\ ");
Just replace the spaces with an escaped space.
Upvotes: 0