I have a third party executable command which is being bundled into my winform application. The command is placed inside a directory called "tools" from the directory where the application is being executed.
For example, if my winform mytestapp.exe is placed in D:\apps\mytestapp directory, then the path to the third party command is D:\apps\mytestapp\tools\mycommand.exe. I'm using Application.StartupPath to identify the location of mytestapp.exe, so that it can be run from any location.
I'm executing this command by starting a process - System.Diagnostics.Process.Start and executing the same using command prompt. There are additional parameters to be passed to run the command.
The problem I'm facing is, if the path to my application and the command does not have any white spaces in it, it works fine
For example, if my app and command is placed like below, it works D:\apps\mytestapp\mytestapp.exe D:\apps\mytestapp\tools\mycommand.exe "parameter1" "parameter2" - this works
however if I have a white space in the path, it fails
C:\Documents and settings\mytestapp\tools\mycommand.exe "parameter1" "parameter2" - doesnt work C:\Documents and settings\mytestapp\tools\mycommand.exe "parameter1 parameter2" - doesnt work "C:\Documents and settings\mytestapp\tools\mycommand.exe" "parameter1 parameter2" - doesnt work "C:\Documents and settings\mytestapp\tools\mycommand.exe parameter1 parameter2" - doesnt work
I tried using double quotes for executing the command as shown above and it doesn't work. So, how do I execute my custom command. Any inputs or work around for this issue? Thanks in advance.
Here is the code for starting the process
try
{
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
proc.WaitForExit();
}
catch (Exception objException)
{
// Log the exception
}