windows – How to write commands in a console program through a batch file (.bat)?

Question:

I want to automate a routine through a .bat that calls a console program that, in turn, will receive successive commands from this .bat . This console program could be, for example, an ftp client.

Example:

c:> BaixarArquivo.bat MeuArquivo.ext

Content BaixarArquivo.bat :

cd /d c:\DiretorioDescarga
ftp 111.222.333.444
ftp> mget %0       // Como fazer um 'output' destes
ftp> quit          //  comandos dentro da .bat?

Considering that the .bat will wait for the program's call to end, how to pass these commands to it?

Answer:

To pass parameters to a .bat :

echo off
echo %1

In the code above I passed the number of the parameter I want to get, in this case it will only be 1:

programa.bat argumento

You can also use the wildcard: %* that it takes all parameters that are passed separated by space.

To store the return of some command you can create a variable: set arg = retorno

Scroll to Top