Batch File Execute Command

electronicsclever
5 min readMay 27, 2021

Download here

So, make an actual batch file: open up notepad, type the commands you want to run, and save as a.bat file. Then double click the.bat file to run it. Try something like this for a start.

How to Run a Batch File from the Command Line on Windows. This wikiHow teaches you how to run a batch file (.BAT) from the Windows command line. You can run the program from the ‘Run’ dialog or by typing commands into a terminal window. Jul 21, 2013 Hi friends, i want to create batch file to execute all my.sql scripts. I have all table ( all table scripts in single file ),Udds ( all udds in single file ),Stored procedures( separate file for each SPs ),Functions ( Separate file for each Functions ),Triggers and views scripts in.SQL file. Can Hi friends, I got this output by these codes.

Active4 months ago

I want to write a batch file that will do following things in given order:

  1. Open cmd
  2. Run cmd command cd c:Program filesIIS Express
  3. Run cmd command iisexpress /path:'C:FormsAdmin.Site' /port:8088 /clr:v2.0
  4. Open Internet Explorer 8 with URL= http://localhost:8088/default.aspx

Note: The cmd window should not be closed after executing the commands.

I tried start cmd.exe /k ‘cd & cd ProgramFilesIIS Express’, but it is not solving my purpose.

Guy Avraham

1,87122 gold badges2424 silver badges3535 bronze badges

patelpatel

51822 gold badges88 silver badges1515 bronze badges

7 Answers

So, make an actual batch file: open up notepad, type the commands you want to run, and save as a .bat file. Then double click the .bat file to run it.

Try something like this for a start:

BlorgbeardBlorgbeard

79.3k4040 gold badges204204 silver badges254254 bronze badges

argentum47argentum47

2,01711 gold badge1212 silver badges1717 bronze badges

This fixes some issues with Blorgbeard’s answer (but is untested):

Community♦

foxidrivefoxidrive

34.9k77 gold badges3737 silver badges6464 bronze badges

cmd /c ‘command’ syntax works well. Also, if you want to include an executable that contains a space in the path, you will need two sets of quotes.

and if your executable needs a file input with a space in the path a another set

FeetyFeety

Peter O.

22.4k99 gold badges6060 silver badges7272 bronze badges

EthanEthan

frankfrank

I know DOS and cmd prompt DOES NOT LIKE spaces in folder names. Your code starts with

cd c:Program filesIIS Express

and it’s trying to go to c:Program in stead of C:’Program Files’

Change the folder name and *.exe name. Hope this helps

user7380371user7380371

protected by Community♦May 15 at 14:53

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Not the answer you’re looking for? Browse other questions tagged batch-filecmdwindows-scripting or ask your own question.

Active1 year, 4 months ago

For the moment my batch file look like this:

The program starts but the DOS Window remains open. How can I close it?

ChrisM

1,34966 gold badges1313 silver badges2424 bronze badges

Mister DevMister Dev

4,1811212 gold badges3636 silver badges3333 bronze badges

11 Answers

You can use the exit keyword. Here is an example from one of my batch files:

Daniel F. Thornton

3,55322 gold badges2323 silver badges4040 bronze badges

Patrick DesjardinsPatrick Desjardins

Bat File Execute Command With Parameters

92.2k7777 gold badges275275 silver badges330330 bronze badges

Use the start command to prevent the batch file from waiting for the program. Just remember to put a empty double quote in front of the program you want to run after ‘Start’.For example, if you want to run Visual Studio 2012 from a batch command:

notice the double quote after start.

MarshallMarshall

2,42111 gold badge88 silver badges22 bronze badges

Look at the START command, you can do this:

For instance, this batch-file will wait until notepad exits:

However, this won’t:

Lasse Vågsæther KarlsenLasse Vågsæther Karlsen

305k8787 gold badges541541 silver badges732732 bronze badges

From my own question:

works if you start the program from an existing DOS session.

If not, call a vb script

The Windows Script Host Run() method takes:

  • intWindowStyle : 0 means ‘invisible windows’
  • bWaitOnReturn : false means your first script does not need to wait for your second script to finish

Here is invis.vbs:

Community♦

VonCVonC

895k329329 gold badges29062906 silver badges34963496 bronze badges

This is the only thing that worked for me when I tried to run a java class from a batch file:

start 'cmdWindowTitle' /B 'javaw' -cp . testprojectpak.MainForm

You can customize the start command as you want for your project, by following the proper syntax:

ZosimasZosimas

You should try this. It starts the program with no window. It actually flashes up for a second but goes away fairly quickly.

Chris DailChris Dail

21.3k99 gold badges5858 silver badges7272 bronze badges

How to solve ‘space problem’ and local dependencies:

GilcoGilco

My solution to do this from the GUI:

  1. Create a shortcut to the program you want to run;
  2. Edit the shortcut’s properties;
  3. Change the TARGET field to %COMSPEC% /C 'START ' 'PROGRAMNAME';
  4. Change the RUN field to minimized.

Ready! See how you like it…

PS: Program parameters can be inserted in between the two final quotation marks; the PROGRAMNAME string can be either a filename, a relative or an absolute path -- if you put in an absolute path and erase the drive letter and semicolon, then this will work in a thumbdrive no matter what letter the host computer assigns to it... (also, if you place the shortcut in the same folder and precede the program filename in PROGRAMNAME with the %CD% variable, paths will always match; same trick can be used in START IN field).

Community♦

Batch File Execute Command In Background

MidasMidas

Batch File Execute Command With Parameters

If this batch file is something you want to run as scheduled or always; you can use windows schedule tool and it doesn’t opens up in a window when it starts the batch file.

To open Task Scheduler:

  • Start -> Run/Search ->'cmd'
  • Type taskschd.msc -> enter

From the right side, click Create Basic Task and follow the menus.

Hope this helps.

LeustadLeustad

Here is my preferred solution. It is taken from an answer to a similar question.

Use a VBS Script to call the batch file:

Copy the lines above to an editor and save the file with .VBS extension.

Community♦

IlyichIlyich

I was having this problem and the following worked for me:

nikcnikc

protected by Community♦Jul 4 ’16 at 17:11

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Write Batch File Execute Commands

Not the answer you’re looking for? Browse other questions tagged windowsbatch-file or ask your own question.

Download here

--

--