aGerman wrote: ↑23 Aug 2022 00:35
Admittedly I never got the point of option /s. Wondering if we already have a thread about that somewhere.
The point of /S is if you want the "old behaviour" (cmd /? mentions "old behavior"). So it forces old behaviour. or to put it another way, it forcibly skips the "new behaviour".
So for example suppose you do CMD /C __________ and either
i) What follows /C fits "new behaviour"
or
ii) What follows /C could vary, so might fit new behaviour or might fit old behaviour.
or
iii) Somebody is aware that for the same thing following _______ it might fit new behaviour or might fit old behaviour.. (e.g. if wordpad.exe isn't on the computer there, then it ridiculously flicks from new to old!)
or
iv) You want peace of mind that it'll follow the "old behaviour".
and e.g. maybe a person just prefers the "old behaviour" to the "new behaviour".
or
They don't like the ambiguity.
There wouldn't be a switch to force "new behaviour", because "new behavour" is very specific. The "New behaviour" is specifically for when you just have a basic situation, of you have an executable filename and the path to it has a space and you want the spaces escaped and are using quotes for that.
'cos in the old behaviour, a simple case of running an EXE when the path has a space, is a bit ugly.
As you can see in the old behaviour, (which I am forcing with /S),
This simple line won't work
Code: Select all
C:\>cmd /S /C "C:\Program Files\Windows NT\Accessories\wordpad.exe"
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
C:\>
(and indeed you've shown how to adjust it so it works for the "old behaviour")
aGerman wrote:Nevertheless, I see how your 2a examples work, because there are no quotes surrounding the command line. 2b probably invokes some kind of undefined behavior since the command line does at least begin with a quote.
it's defined behaviour..
Considering case "2"(so-called old style),which describes two possible cases. 2b(that's meant to be for quotes around the command line), and 2a(where it acts like they are not quotes around the command line and that they are for escaping special characters - besides space). And it tests for 2b by as per the documentation, by looking to see if the first character is a quote..
So 2b is the ("Look for the first quote") case.
The example I gave fitting 2b, is actually defined in cmd /?'s write up for case 2.
Code: Select all
..old 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.
What it hasn't said, is that case "2" has two possible purposes. One of them, which is described there, is for when there are quotes around the command line. What it describes there is a broken form of quotes around the command line.
So my example just fits very much with what they wrote.. It's very defined.
They didn't define any case of "2" as being for quotes around the command line.
The quotes around the command line concept makes sense to me for linux but not for CMD. 'cos CMD doesn't use argv(i.e. it doesn't take arguments delimited by space), it just takes the whole command line anyway!
What is undefined , is what I described as the "2a"(No first quote) case.. I think what happens is won't follow the "new behaviour" or the "old behaviour", it will Normal behaviour.
So in a sense one could say that instead of saying there's "new behaviour", "old behaviour A", and "old behaviour B". . One could say there's a "3" which is follow normal behaviour. (as if one were at CMD and not doing /c).
So cmd /? could say that when doing /C or /K it will do 1 or 2 or 3. Where 1 is the new behaviour, 2 is the first quote case, and 3 is the normal behaviour. And dit does 1 otherwise 2 otherwise 3.
aGerman wrote:
I actually just repeated how the OS builds the command line if you run a Batch file.
Code: Select all
@echo off
setlocal EnableDelayedExpansion
echo !cmdcmdline!
pause
If you run it via double click you may see something like that:
Code: Select all
C:\WINDOWS\system32\cmd.exe /c ""C:\Users\steffen\Documents\test.bat" "
Drücken Sie eine beliebige Taste . . .
If you drag drop a file onto it:
Code: Select all
C:\WINDOWS\system32\cmd.exe /c ""C:\Users\steffen\Documents\test.bat" C:\Users\steffen\Documents\test.txt"
Drücken Sie eine beliebige Taste . . .
So, you won't go wrong following this syntax, I guess.
That's really good, so by testing double clicking a bat, or drag and dropping a file onto the cmd window, you figured out the purpose of what they call "old behaviour". particularly the "first quote" case of "2".. Which is the only case mentioned in "2"..
You figured out that it's meant for when there are quotes around the command line.
Old behaviour is a bit ugly, so they came up with "new behaviour", which is for the very specific case of just there's two quotes spaces e.g..
CMD /C "path with spaces to wordpad.exe"
though the so-called "new behaviour" becomes ugly when that exe doesn't exist!
A person could just use the syntax that involves more than two quotes, and thus hits that way, onto the "old behaviour". and always using "old behaviour" the way it is really intended which is for quotes around the command line. (not having text after the command line)
It does open the question which I asked in another thread of what system uses old behaviour (and not "new behaviour")!!
Presumably there is one hence they call it "old behaviour"!!!
BTW i'm going to take a guess that they chose /S for "surround"..
Note- I could say /S forcibly skips "new behaviour", rather than that /S forces "old behaviour" because what kind of case would one call cmd /C abc"^"def
Code: Select all
C:\Users\User>cmd /c abc"^"def
'abc"^"def' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\User>abc"^"def
'abc"^"def' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\User>
I'd say It's normal behaviour.
So there aren't really two cases of old behaviour..
It's silly that cmd /? only mentions that /C doesn't mention that as a third option for when a case doesn't match the "surrounding quotes" method of old behaviour (by not starting with a quote)