0

I need four command prompt commands to run in one batch file. It should run from top to bottom. The commands are:

ipconfig /flushdns
ipconfig /release
ipconfig /renew
exit
1
  • just add it in line in a file and run the shell script file.
    – Naruto
    Commented Sep 25, 2016 at 8:43

2 Answers 2

11

To perform commands in a batch file, first of all start it with @echo off then put your first command, then second.... and then you can end it with exit (Though it isn't 100% neccesary)

@echo off    
ipconfig /flushdns
ipconfig /release
ipconfig /renew
exit /b

To save this as a batch file do the following:

  1. Press WIN+R
  2. Type in notepad
  3. Press enter (or click OK)
  4. Type the above script into the text editor (or copy & paste it)
  5. Press CTRL+S (or click File > save)
  6. In the Save as type: list, select All files (*.*)
  7. Give your batch file a name and end it with .bat
  8. Click on Save or press ENTER

And that's it, your batch file will now perform the specified commands when it's launched

3
  • 1
    5a. be sure to change the coding to ANSI.
    – Stephan
    Commented Sep 25, 2016 at 9:30
  • @Stephan Notepad defaults to ANSI every time the save dialog opens, but I take your point
    – Sam Denty
    Commented Sep 25, 2016 at 10:12
  • well, it didn't on my windows - until I changed it once. Since then, it also defaults to ANSI.
    – Stephan
    Commented Sep 26, 2016 at 6:05
-1

You mean four commands to run from one batch file. Actually that's what batch files are for!

1.Open Notepad or any text editor.
2.Type each command on a separate line, in the order you want.
3. Save the file as firstBatch.bat 4. Close your text editor.

When you run that batch file (I hope you know how), they will all run as you want.

3
  • 1
    I have tried and only first command is executed not the second one. How I can execute the the both commands?
    – Zohair
    Commented Aug 21, 2019 at 13:31
  • Is the first command one that finishes? Or is it still running? If you run it from the command line does it go back to the prompt? Commented Aug 22, 2019 at 14:35
  • 1
    First command finish its execution and the next one do not executes.
    – Zohair
    Commented Aug 22, 2019 at 15:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.