@sst, thanks, you're spot on, I hadn't realised that the round brackets / parentheses , when occurring in a parameter, don't group things! (is that right?)
You solved it though. I like both those solutions, the quotes one, and the escaping the ampersand one.
you explained that very well with how the parameters are broken down.. I tested it and indeed
(w.c and w2.c referenced at bottom of post)
Code: Select all
C:\>w cmd /k echo abc & echo def
argv[0] = w
argv[1] = cmd
argv[2] = /k
argv[3] = echo
argv[4] = abc
def
C:\>w cmd /k echo (abc & echo def)
argv[0] = w
argv[1] = cmd
argv[2] = /k
argv[3] = echo
argv[4] = (abc
def)
C:\>
C:\>w cmd /k echo abc ^& echo def
argv[0] = w
argv[1] = cmd
argv[2] = /k
argv[3] = echo
argv[4] = abc
argv[5] = &
argv[6] = echo
argv[7] = def
So I see the importance of the quotes there.. or the escaping the ampersand
Funnily enough this doesn't work
C:\>start cmd /k echo abc "&" echo def
even though the argsv come out the same
Code: Select all
C:\>w cmd /k echo abc "&" echo def
argv[0] = w
argv[1] = cmd
argv[2] = /k
argv[3] = echo
argv[4] = abc
argv[5] = &
argv[6] = echo
argv[7] = def
Though the command line is different for them,
C:\>w2 start cmd /k echo abc "&" echo def
w2 start cmd /k echo abc "&" echo def
C:\>w2 start cmd /k echo abc ^& echo def
w2 start cmd /k echo abc & echo def
C:\>
so maybe start uses some kind of mixture of first getting the command line then splitting into arguments
@elz , well spotted re quotes around the echo, though I think the start "" is a bit of a red herring here.. it's not necessary. It is necessary when the path to the executable contains a space. e.g. C:\>start c:\crp\zzzza.bat works, but C:\>start "c:\crp\bab zab\fafa.bat" fails and requires C:\>start "" "c:\crp\bab zab\fafa.bat" So there are cases when you need the "" but not here.
@sst could solution and explanation.
Thanks guys
* w.c and w2.c
https://pastebin.com/raw/KTWihmPB