Search code examples
windowsshellexecute

Run tool does not works


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"


Solution

  • 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""