How to execute more than one waiting command in a file . bat

Asked

Viewed 1,339 times

1

I searched here and could not find how to do it. In short I need to create a file .bat and execute 3 commands:

1. Open a directory ( cd );

2. Execute ( npm i );

after completion of the above task

3. Run a . js in Node.

  • With a little research I found the command call, who makes the call from another file .bat and pause the execution until the completion of the .bat called. The links I found if you want to take a look: link1, Link2

  • 1

    All commands execute in order until the previous one is completed, that is, all of them wait, unless the behavior of a specific command is very different, if you put them all inside one. Bat with line break will run in order

  • Have you ever tested John Paul? because as already mentioned it is very likely that there is no need to add a waiting command.

  • @Tuxpilgrim In the tests I did he stopped after the CD, probably because I made some syntax error. I’ll check with these tips.

  • I did a test according to what Thiago Magalhães went through. My only problem now is that the window is closing and needs to be open.

1 answer

2


You can create a normal bat file with a command on each line. When running the bat it will execute the commands in sequence and wait for the command to finish running the next one, that is, if you put the npm install command, the following commands will only be executed when the installation is finished.

An example of how the bat file would look:

cd usuario echo %cd% npm i nodemon nodemon index.js

  • After executed the commands need that the window remains open, but apparently it is working until this part.

  • Add the command pause at the end of the file, with this it will only close if you press some key.

  • Even with pause the window is closing. Actually I can’t tell if it even runs the 3rd command.

  • If a command fails, the pause will not work. Probably the error is in the installation you are trying to do. For pause to work in this case, put the command call before the command you think may be giving error. For example: call npm i nodemon.

  • This call in the installation solved and is now running perfectly. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.