I am trying to invoke one executable by putting following line on command prompt. (I know I can directly invoke the exe but let's just say I have no other way to do this due to some restriction)
"cmd /C" "C:\\Program Files\ABC\xyz.exe" -register="abc"
itself It is successfully run. /C is parameter to cmd.exe. But when I do this
"C:\Windows\System32\cmd.exe /C" "C:\\Program Files\ABC\xyz.exe" -register="abc"
Gives me error
The directory name is invalid
Any idea why? And how can I solve this problem? I have to use full path of cmd.exe.
Try this instead:
"C:\Windows\System32\cmd.exe" /C " "C:\\Program Files\ABC\xyz.exe" -register="abc" "
For example:
"C:\Windows\System32\cmd.exe" /C " echo "Hello World" "
"C:\Windows\System32\cmd.exe" /C " python -c " print 'Hello World' "
These work without any problem and both of them output "Hello World"
As stated by Stephan, the correct way of writing it is some of the following options
"C:\Windows\System32\cmd.exe" /C ....
"%comspec%" /c ....
The question is Why "cmd /c" .... works? It works for the way the parser is interpreting the line.
When the line is readed and parsed, "cmd /c" is converted to
execute the command interpreter with the /c" ... arguments
So it is executed as
%comspec% /c ".....
This substitution can be easily tested
set "ComSpec=c:\windows\system32\calc.exe"
"cmd /c" echo hello
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With