3

I need a DOS .bat script that just transfers ALL arguments to a .exe program.

For example the DOS script main.bat that calls the .exe program.exe:

program.exe ????

The question is what ??? should be. The arguments must ALL be passed quoted: if there are filenames with spaces, these must be left intact. Under UNIX/POSIX this is called "quoted array", because the arguments form an array (ARGV[x]), and each argument must be quoted.

davidbaumann
  • 2,289

1 Answers1

3

You can simply use %* to pass everything that was passed to the .bat file to anything else.

Note that if you pass "words with spaces" to the batch file, it will be seen as 1 parameter in quotes and passed as that. If you ommit the "", the batch will still forward it to the program, but the program will see it as separate parameters. It really depends on how the batch file is called to know if those quotes will be there or not and if needed. For example, if you drag and drop a file in explorer onto the batchfile, explorer will add the quotes for you. If you type manually from the command prompt, its up to the user to check for the quotes.

So:

program.exe %0

should be enough in your case.

Also, from commandline, if you autocomplete filenames with the tab, quotes are automatically added if they are necessary, and even while the quotes may make it seem that you have to edit them out in order to continue typing, you really don't have to. Command prompt is smart enough.

Example: here I type prog, press tab twice, then continue typing and press tab once more.

C:\>_

C:\>cd prog_  (tab)

C:\>cd "Program Files"_  (tab)

C:\>cd "Program Files (x86)"_

C:\>cd "Program Files (x86)"\Micro_    (tab)

C:\>cd "Program Files (x86)\Microsoft Office"_    (enter)

C:\Program Files (x86)\Microsoft Office>_
LPChip
  • 66,193