When I use Windows Run tool to call my exe with argument it work fine I did below cmd.exe /C "C:\ex\abc.exe" skk Then my exe get a hit and i got skk as an argument. BUt I i did cmd.exe /C "C:\ex\abc.exe" "sk k" then my exe does not call. Why? But the same thing work fine in cmd line "C:\ex\abc.exe" "sk k"
Asked
Active
Viewed 33 times
1 Answers
2
This is by design
If more than two quote characters are present after the /C switch, then "behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character.", unless the following conditions are met:
- no /S switch
- exactly two quote characters
- no special characters between the two quote characters, where special is one of: &<>()@^|
- there are one or more whitespace characters between the two quote characters
- the string between the two quote characters is the name of an executable file.
So, when you do
cmd.exe /C "C:\ex\abc.exe" "sk k"
it's trying to execute
C:\ex\abc.exe" "sk k
which, obviously, doesn't work. If you want to run your exe with an argument containing the whitespace, try
cmd.exe /C C:\ex\abc.exe "sk k"
Or wrap the the whole command in double quotes like so:
cmd.exe /C ""C:\New Folder\abc.exe" "sk k""

Maksim Satsikau
- 1,444
- 11
- 11
-
Yes, it works. but what happens if my abc.exe is in "New Folder"? I need to do this cmd.exe /C "C:\New Folder\abc.exe" "sk k". This is not working. Now What I need to do. – San Nov 16 '14 at 07:12
-
Then wrap the whole command in double quotes (see corrected answer above) – Maksim Satsikau Nov 16 '14 at 07:20