Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmd- comma to separate parameters Compared to space?

I have some questions on the subject, of commas compared to space, in delimiting parameters.

They are questions that C programmers familiar with the cmd prompt, may be able to throw some light on..

I know that when doing

c:\>program a b c

there are 4 parameters [0]=program [1]=a [2]=b [3]=c

According to hh ntcmds.chm concepts..

Shell overview

; and , are used to separate parameters

; or , command1 parameter1;parameter2  Use to separate command parameters.

I see dir a,b gives the same result as dir a b

but

c:\>program a,b,c gives parameters [0]=program [1]=a,b,c

So do some? or all? windows commands use ; and , ? and is that interpretation within the code of each command, or done by the shell like with space?

And if it is in the code of each command.. how would I know which do it? I notice that documentation of explorer.exe mentions the comma,e.g. you can do explorer /e,.

but DIR /? does not mention it, but can use it. And a typical c program doesn't take , as a delimiter at all.. So is it the case that the shell doesn't use comma to delimit, it uses space. And windows commands that do, do so 'cos they are (all?) written to delimit the parameters the shell has given them further when commas are used?

like image 353
barlop Avatar asked Nov 11 '10 16:11

barlop


People also ask

What can I use instead of space in CMD?

In the Command Prompt, the caret character ( ^ ) will let you escape spaces—in theory. Just add it before each space in the file name. (You'll find this character in the number row on your keyboard.

How do I escape special characters in CMD?

The Windows command-line interpreter uses a caret character ( ^ ) to escape reserved characters that have special meanings (in particular: & , | , ( , ) , < , > , ^ ).

How do I escape double quotes in CMD?

Double quotes enable escaping through the use of the backslash (\). For example, if the special character semicolon is a value that is double-quoted, it should be represented as backslash semicolon (\;) so that the Integration Engine knows that the actual value (;) should be used.

How do I use special characters in CMD?

You can put the arguments in quotes: myprogram.exe "(this is some text, with special characters.)"


1 Answers

There are two differences here between Unix and Windows:

  • Internal commands such as DIR are built into the shell; their command line syntax doesn't have to follow the same rules as for regular programs
  • On Windows, programs are responsible for parsing their own command lines. The shell parses redirects and pipes, then passes the rest of the command line to the program in one string

Windows C programs built using Visual Studio use the command line parser in the Microsoft C runtime, which is similar to a typical Unix shell parser and obeys spaces and quotation marks.

I've never seen a C program that uses , or ; as a command line separator. I was aware of the special case for explorer /e,., but I'd never seen the dir a,b example until just now.

like image 161
Tim Robinson Avatar answered Sep 26 '22 14:09

Tim Robinson