Pass arguments of .BAT file to executed .EXE file [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • does %* in batch file mean all command line arguments?

    1 answer




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.










share|improve this question









New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











marked as duplicate by LPChip, slhck, harrymc, PeterH, Toto Nov 14 at 10:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Hi there, and welcome to SuperUser. We're not a "Please write me a script" kind of website. If you share us your script, we can help you narrow down why things aren't working though. That said, it is a bit hard to understand your goal, and an accompanying script would definitely help with that.
    – LPChip
    Nov 13 at 11:07










  • The basic problem is that there are 2 .exe's: one for the 32 bit version, and one for the 64 bit version. Let's call them program32.exe and program64.exe. These names can't be changed at the moment. However, I want to write generic scripts that call on of thes .exe's depending on the installation. I just have to know how in DOS you can pass arguments in a quoted way. I don't need a real script. I need 1 onliner. Eg: if i type:
    – Francky Leyn
    Nov 13 at 11:41










  • 'main.bat "filename with spaces.jpg"', this must be , for the 64 bit version, reult in the DOS system call 'program64.exe "filename with spaces.jpg"'
    – Francky Leyn
    Nov 13 at 11:44















up vote
0
down vote

favorite













This question already has an answer here:




  • does %* in batch file mean all command line arguments?

    1 answer




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.










share|improve this question









New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











marked as duplicate by LPChip, slhck, harrymc, PeterH, Toto Nov 14 at 10:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Hi there, and welcome to SuperUser. We're not a "Please write me a script" kind of website. If you share us your script, we can help you narrow down why things aren't working though. That said, it is a bit hard to understand your goal, and an accompanying script would definitely help with that.
    – LPChip
    Nov 13 at 11:07










  • The basic problem is that there are 2 .exe's: one for the 32 bit version, and one for the 64 bit version. Let's call them program32.exe and program64.exe. These names can't be changed at the moment. However, I want to write generic scripts that call on of thes .exe's depending on the installation. I just have to know how in DOS you can pass arguments in a quoted way. I don't need a real script. I need 1 onliner. Eg: if i type:
    – Francky Leyn
    Nov 13 at 11:41










  • 'main.bat "filename with spaces.jpg"', this must be , for the 64 bit version, reult in the DOS system call 'program64.exe "filename with spaces.jpg"'
    – Francky Leyn
    Nov 13 at 11:44













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • does %* in batch file mean all command line arguments?

    1 answer




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.










share|improve this question









New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












This question already has an answer here:




  • does %* in batch file mean all command line arguments?

    1 answer




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.





This question already has an answer here:




  • does %* in batch file mean all command line arguments?

    1 answer








array






share|improve this question









New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 13 at 11:17









davidbaumann

1,667721




1,667721






New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 13 at 10:52









Francky Leyn

102




102




New contributor




Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Francky Leyn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




marked as duplicate by LPChip, slhck, harrymc, PeterH, Toto Nov 14 at 10:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by LPChip, slhck, harrymc, PeterH, Toto Nov 14 at 10:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Hi there, and welcome to SuperUser. We're not a "Please write me a script" kind of website. If you share us your script, we can help you narrow down why things aren't working though. That said, it is a bit hard to understand your goal, and an accompanying script would definitely help with that.
    – LPChip
    Nov 13 at 11:07










  • The basic problem is that there are 2 .exe's: one for the 32 bit version, and one for the 64 bit version. Let's call them program32.exe and program64.exe. These names can't be changed at the moment. However, I want to write generic scripts that call on of thes .exe's depending on the installation. I just have to know how in DOS you can pass arguments in a quoted way. I don't need a real script. I need 1 onliner. Eg: if i type:
    – Francky Leyn
    Nov 13 at 11:41










  • 'main.bat "filename with spaces.jpg"', this must be , for the 64 bit version, reult in the DOS system call 'program64.exe "filename with spaces.jpg"'
    – Francky Leyn
    Nov 13 at 11:44


















  • Hi there, and welcome to SuperUser. We're not a "Please write me a script" kind of website. If you share us your script, we can help you narrow down why things aren't working though. That said, it is a bit hard to understand your goal, and an accompanying script would definitely help with that.
    – LPChip
    Nov 13 at 11:07










  • The basic problem is that there are 2 .exe's: one for the 32 bit version, and one for the 64 bit version. Let's call them program32.exe and program64.exe. These names can't be changed at the moment. However, I want to write generic scripts that call on of thes .exe's depending on the installation. I just have to know how in DOS you can pass arguments in a quoted way. I don't need a real script. I need 1 onliner. Eg: if i type:
    – Francky Leyn
    Nov 13 at 11:41










  • 'main.bat "filename with spaces.jpg"', this must be , for the 64 bit version, reult in the DOS system call 'program64.exe "filename with spaces.jpg"'
    – Francky Leyn
    Nov 13 at 11:44
















Hi there, and welcome to SuperUser. We're not a "Please write me a script" kind of website. If you share us your script, we can help you narrow down why things aren't working though. That said, it is a bit hard to understand your goal, and an accompanying script would definitely help with that.
– LPChip
Nov 13 at 11:07




Hi there, and welcome to SuperUser. We're not a "Please write me a script" kind of website. If you share us your script, we can help you narrow down why things aren't working though. That said, it is a bit hard to understand your goal, and an accompanying script would definitely help with that.
– LPChip
Nov 13 at 11:07












The basic problem is that there are 2 .exe's: one for the 32 bit version, and one for the 64 bit version. Let's call them program32.exe and program64.exe. These names can't be changed at the moment. However, I want to write generic scripts that call on of thes .exe's depending on the installation. I just have to know how in DOS you can pass arguments in a quoted way. I don't need a real script. I need 1 onliner. Eg: if i type:
– Francky Leyn
Nov 13 at 11:41




The basic problem is that there are 2 .exe's: one for the 32 bit version, and one for the 64 bit version. Let's call them program32.exe and program64.exe. These names can't be changed at the moment. However, I want to write generic scripts that call on of thes .exe's depending on the installation. I just have to know how in DOS you can pass arguments in a quoted way. I don't need a real script. I need 1 onliner. Eg: if i type:
– Francky Leyn
Nov 13 at 11:41












'main.bat "filename with spaces.jpg"', this must be , for the 64 bit version, reult in the DOS system call 'program64.exe "filename with spaces.jpg"'
– Francky Leyn
Nov 13 at 11:44




'main.bat "filename with spaces.jpg"', this must be , for the 64 bit version, reult in the DOS system call 'program64.exe "filename with spaces.jpg"'
– Francky Leyn
Nov 13 at 11:44










1 Answer
1






active

oldest

votes

















up vote
0
down vote













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>_





share|improve this answer





















  • If you have a .bat script, must I then return a status code? look at this:
    – Francky Leyn
    2 days ago










  • No, you do not need to return a status code. By default, any command in the script will alter the statuscode depending on its outcome, and that is stored in %errorlevel%^. Bat files themselves don't alter this unless you specifically do so, and its not necessary.
    – LPChip
    2 days ago










  • Comments are not meant to post code. Your original question has been answered. I suggest posting a new question with the code in a codeblock and we can help you why things are not working as expected.
    – LPChip
    2 days ago










  • Only in questions can you post them. A codeblock is written by typing 4 or more spaces at the start of a line. See also the formatting help when you make a new question.
    – LPChip
    yesterday


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













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>_





share|improve this answer





















  • If you have a .bat script, must I then return a status code? look at this:
    – Francky Leyn
    2 days ago










  • No, you do not need to return a status code. By default, any command in the script will alter the statuscode depending on its outcome, and that is stored in %errorlevel%^. Bat files themselves don't alter this unless you specifically do so, and its not necessary.
    – LPChip
    2 days ago










  • Comments are not meant to post code. Your original question has been answered. I suggest posting a new question with the code in a codeblock and we can help you why things are not working as expected.
    – LPChip
    2 days ago










  • Only in questions can you post them. A codeblock is written by typing 4 or more spaces at the start of a line. See also the formatting help when you make a new question.
    – LPChip
    yesterday















up vote
0
down vote













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>_





share|improve this answer





















  • If you have a .bat script, must I then return a status code? look at this:
    – Francky Leyn
    2 days ago










  • No, you do not need to return a status code. By default, any command in the script will alter the statuscode depending on its outcome, and that is stored in %errorlevel%^. Bat files themselves don't alter this unless you specifically do so, and its not necessary.
    – LPChip
    2 days ago










  • Comments are not meant to post code. Your original question has been answered. I suggest posting a new question with the code in a codeblock and we can help you why things are not working as expected.
    – LPChip
    2 days ago










  • Only in questions can you post them. A codeblock is written by typing 4 or more spaces at the start of a line. See also the formatting help when you make a new question.
    – LPChip
    yesterday













up vote
0
down vote










up vote
0
down vote









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>_





share|improve this answer












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>_






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 at 12:24









LPChip

34.7k44982




34.7k44982












  • If you have a .bat script, must I then return a status code? look at this:
    – Francky Leyn
    2 days ago










  • No, you do not need to return a status code. By default, any command in the script will alter the statuscode depending on its outcome, and that is stored in %errorlevel%^. Bat files themselves don't alter this unless you specifically do so, and its not necessary.
    – LPChip
    2 days ago










  • Comments are not meant to post code. Your original question has been answered. I suggest posting a new question with the code in a codeblock and we can help you why things are not working as expected.
    – LPChip
    2 days ago










  • Only in questions can you post them. A codeblock is written by typing 4 or more spaces at the start of a line. See also the formatting help when you make a new question.
    – LPChip
    yesterday


















  • If you have a .bat script, must I then return a status code? look at this:
    – Francky Leyn
    2 days ago










  • No, you do not need to return a status code. By default, any command in the script will alter the statuscode depending on its outcome, and that is stored in %errorlevel%^. Bat files themselves don't alter this unless you specifically do so, and its not necessary.
    – LPChip
    2 days ago










  • Comments are not meant to post code. Your original question has been answered. I suggest posting a new question with the code in a codeblock and we can help you why things are not working as expected.
    – LPChip
    2 days ago










  • Only in questions can you post them. A codeblock is written by typing 4 or more spaces at the start of a line. See also the formatting help when you make a new question.
    – LPChip
    yesterday
















If you have a .bat script, must I then return a status code? look at this:
– Francky Leyn
2 days ago




If you have a .bat script, must I then return a status code? look at this:
– Francky Leyn
2 days ago












No, you do not need to return a status code. By default, any command in the script will alter the statuscode depending on its outcome, and that is stored in %errorlevel%^. Bat files themselves don't alter this unless you specifically do so, and its not necessary.
– LPChip
2 days ago




No, you do not need to return a status code. By default, any command in the script will alter the statuscode depending on its outcome, and that is stored in %errorlevel%^. Bat files themselves don't alter this unless you specifically do so, and its not necessary.
– LPChip
2 days ago












Comments are not meant to post code. Your original question has been answered. I suggest posting a new question with the code in a codeblock and we can help you why things are not working as expected.
– LPChip
2 days ago




Comments are not meant to post code. Your original question has been answered. I suggest posting a new question with the code in a codeblock and we can help you why things are not working as expected.
– LPChip
2 days ago












Only in questions can you post them. A codeblock is written by typing 4 or more spaces at the start of a line. See also the formatting help when you make a new question.
– LPChip
yesterday




Only in questions can you post them. A codeblock is written by typing 4 or more spaces at the start of a line. See also the formatting help when you make a new question.
– LPChip
yesterday



Popular posts from this blog

Сан-Квентин

Алькесар

Josef Freinademetz