Batch File Execute Command

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. 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. On Windows 10, a batch file is a special kind of text file that typically uses a.bat extension, which can include one or multiple commands that Command Prompt can understand and run in sequence.

Active3 months ago

I'm trying to make my Visual Studio build script execute a .bat file that does something important.

Here is what I'm want to do right now:

But it doesn't work.

I have to do this to make it work:

But this is pretty difficult to add to the Visual Studio script.

How can I do this in one single line?

Mofi
31.4k8 gold badges42 silver badges91 bronze badges
BingBang32BingBang32

4 Answers

Bugs
4,2009 gold badges27 silver badges37 bronze badges
jwganjwgan

'F:- Big Packets -kitterengineCommonTemplate.bat' maybe prefaced with call (see call /?). Or Cd /d 'F:- Big Packets -kitterengineCommon' & Template.bat.

CMD Cheat Sheet

  • Cmd.exe

  • Getting Help

  • Punctuation

  • Naming Files

  • Starting Programs

  • Keys

CMD.exe

First thing to remember its a way of operating a computer. It's the way we did it before WIMP (Windows, Icons, Mouse, Popup menus) became common. It owes it roots to CPM, VMS, and Unix. It was used to start programs and copy and delete files. Also you could change the time and date.

For help on starting CMD type cmd /?. You must start it with either the /k or /c switch unless you just want to type in it.

Getting Help

For general help. Type Help in the command prompt. For each command listed type help <command> (eg help dir) or <command> /? (eg dir /?).

Some commands have sub commands. For example schtasks /create /?.

The NET command's help is unusual. Typing net use /? is brief help. Type net help use for full help. The same applies at the root - net /? is also brief help, use net help.

References in Help to new behaviour are describing changes from CMD in OS/2 and Windows NT4 to the current CMD which is in Windows 2000 and later.

WMIC is a multipurpose command. Type wmic /?.

Punctuation

Naming Files

Starting a Program

See start /? and call /? for help on all three ways.

There are two types of Windows programs - console or non console (these are called GUI even if they don't have one). Console programs attach to the current console or Windows creates a new console. GUI programs have to explicitly create their own windows.

If a full path isn't given then Windows looks in

  1. The directory from which the application loaded.

  2. The current directory for the parent process.

  3. Windows NT/2000/XP: The 32-bit Windows system directory. Use theGetSystemDirectory function to get the path of this directory. Thename of this directory is System32.

  4. Windows NT/2000/XP: The 16-bit Windows system directory. There is nofunction that obtains the path of this directory, but it issearched. The name of this directory is System.

  5. The Windows directory. Use the GetWindowsDirectory function to getthe path of this directory.

  6. The directories that are listed in the PATH environment variable.

Specify a program name

This is the standard way to start a program.

In a batch file the batch will wait for the program to exit. Whentyped the command prompt does not wait for graphicalprograms to exit.

If the program is a batch file control is transferred and the rest of the calling batch file is not executed.

Use Start command

Start starts programs in non standard ways.

Start starts a program and does not wait. Console programs start in a new window. Using the /b switch forces console programs into the same window, which negates the main purpose of Start.

Command

Start uses the Windows graphical shell - same as typing in WinKey + R (Run dialog). Try

Also program names registered under HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionApp Paths can also be typed without specifying a full path.

Also note the first set of quotes, if any, MUST be the window title.

Use Call command

Call is used to start batch files and wait for them to exit and continue the current batch file.

Other Filenames

Typing a non program filename is the same as double clicking the file.

Keys

Ctrl + C exits a program without exiting the console window.

For other editing keys type Doskey /?.

  • and recall commands

  • ESC clears command line

  • F7 displays command history

  • ALT+F7 clears command history

  • F8 searches command history

  • F9 selects a command by number

  • ALT+F10 clears macro definitions

Also not listed

  • Ctrl + or Moves a word at a time

  • Ctrl + Backspace Deletes the previous word

  • Home Beginning of line

  • End End of line

  • Ctrl + End Deletes to end of line

temporary_user_name
17.6k32 gold badges103 silver badges170 bronze badges
user6017774

There are many possibilities to solve this task.

1. RUN the batch file with full path

The easiest solution is running the batch file with full path.

Once end of batch file Template.bat is reached, there is no return to previous script in case of the command line above is within a *.bat or *.cmd file.

The current directory for the batch file Template.bat is the current directory of the current process. In case of Template.bat requires that the directory of this batch file is the current directory, the batch file Template.bat should contain after @echo off as second line the following command line:

Run in a command prompt window cd /? for getting displayed the help of this command explaining parameter /D ... change to specified directory also on a different drive.

Run in a command prompt window call /? for getting displayed the help of this command used also in 2., 4. and 5. solution and explaining also %~dp0 ... drive and path of argument 0 which is the name of the batch file.

2. CALL the batch file with full path

Another solution is calling the batch file with full path.

The difference to first solution is that after end of batch file Template.bat is reached the batch processing continues in batch script containing this command line.

For the current directory read above.

3. Change directory and RUN batch file with one command line

There are 3 operators for running multiple commands on one command line: &, && and ||.
For details see answer on Single line with multiple commands using Windows batch file

I suggest for this task the && operator.

As on first solution there is no return to current script if this is a *.bat or *.cmd file and changing the directory and continuation of batch processing on Template.bat is successful.

4. Change directory and CALL batch file with one command line

This command line changes the directory and on success calls the batch file.

The difference to third solution is the return to current batch script on exiting processing of Template.bat.

Batch File Execute Command Manager

5. Change directory and CALL batch file with keeping current environment with one command line

The four solutions above change the current directory and it is unknown what Template.bat does regarding

  1. current directory
  2. environment variables
  3. command extensions state
  4. delayed expansion state

In case of it is important to keep the environment of current *.bat or *.cmd script unmodified by whatever Template.bat changes on environment for itself, it is advisable to use setlocal and endlocal.

Run in a command prompt window setlocal /? and endlocal /? for getting displayed the help of these two commands. And read answer on change directory command cd ..not working in batch file after npm install explaining more detailed what these two commands do.

File

Now there is only & instead of && used as it is important here that after setlocal is executed the command endlocal is finally also executed.

ONE MORE NOTE

If batch file Template.bat contains the command exit without parameter /B and this command is really executed, the command process is always exited independent on calling hierarchy. So make sure Template.bat contains exit /B or goto :EOF instead of just exit if there is exit used at all in this batch file.

Community
MofiMofi
31.4k8 gold badges42 silver badges91 bronze badges

You Can Use Cmd Command To Run Batch File.

Here Is My Way =>

More Information =>cmd /?

Bat File Execute Command

scientist_7scientist_7

Batch File Execute Command Line

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