Questions tagged [batch-file]

A batch file is a text file containing a series of commands that are executed by the command interpreter on MS-DOS, IBM OS/2, or Microsoft Windows systems.

Batch files are text-based scripts, usually saved with the .bat, .cmd, or .btm filename extension. They are executed by the command processor (typically COMMAND.COM on MS-DOS and earlier versions of Windows, cmd.exe on IBM OS/2 and later version of Windows). Note that, while batch files are still supported under Windows, recent versions have the much more expansive PowerShell.

Example

This is the source code to a typical "Hello world" program in batch programming:

@ECHO off
ECHO Hello World!
PAUSE

Note the ! may not display if delayed expansion is enabled.

Tag usage

The tag can be used for programming-related problems in writing a batch script file for a Windows-based operating system. Please avoid "suggest a book"-type questions. Note the tag is not to be used for questions referring to a "batch of files" or referring to the "Spring Batch" framework but for questions related to the shell language only.

Useful links

See also:

53766 questions
10
votes
2 answers

How to make a batch file execute a reg file

I have the following code @echo off file.reg pause This works but when the batch file is elevated I get an error saying that it cannot find the file. does any one know what I am doing wrong.
09stephenb
  • 9,358
  • 15
  • 53
  • 91
10
votes
1 answer

How to execute a windows batch command recursively?

For example, you have a rename command in a batch file, and you want to execute that file on the current directory and all sub-directories.
Bassel Alkhateeb
  • 1,584
  • 5
  • 19
  • 35
10
votes
4 answers

Batch file set wmi output as a variable

Hello having my first go with a BATCH script, I'm getting the size of the HDD as follow: wmic diskdrive get size Which works fine but I'd like to store this value into a variable for later use, such as using ECHO to display the value. I'm not sure…
twigg
  • 3,753
  • 13
  • 54
  • 96
10
votes
4 answers

Building a batch file to run exe files sequentially

I just start to learn how to build batch file. ( on the windows 7 environment) I want to build the batch file which is able to run .exe files sequentially . Run batch files sequentially I was trying to apply above idea but I am not really sure how…
Dc Redwing
  • 1,681
  • 11
  • 32
  • 42
10
votes
6 answers

Using robocopy with source and destination as variables

Completely new to scripting, tried to find a solution through searching the web but I'm stumped, so asking for help please! I'm trying to use robocopy with a variable as both the source and destination, different one for each, but I just can't get…
lcllm7
  • 101
  • 1
  • 1
  • 3
10
votes
1 answer

batch file fails to set variable in IF clause

The following code is not updating Run to equal N even though the match occurs. this means I'm not dropping into the CALL code. Am i missing something here? SET Run=Y REM Check current files date/time information and establish if the file has been…
sapatos
  • 1,292
  • 3
  • 21
  • 44
10
votes
4 answers

How to add optional command line parameter in bat file ( windows )

I have a batch file in with the following parameter hard coded SET upgrade=false I want to give user an option to explicitly define the upload parameter. By default it should be false and if user explicitly define upgrade=true I should treat it as…
Abhishek Goel
  • 18,785
  • 11
  • 87
  • 65
10
votes
2 answers

Run interactive batch in Visual Studio post build events

I have a program written in vb.net. After I build, I want to launch an interactive batch file that executes a psexec command remotely. How can I do that? this is my post build event: call "$(ProjectDir)ExecOnGw.bat" And this is my batch that if it…
davymartu
  • 1,393
  • 3
  • 15
  • 34
10
votes
2 answers

Copy file from batch file's directory

I know only the very basics of writing batch files. I am trying to figure out how to write one that, given any directory it is in, would copy a file that is within the same directory and put it in a new location. I know how to copy the file and…
Kyle Wright
  • 520
  • 2
  • 9
  • 23
10
votes
5 answers

Run batch file from Java code

I am trying to run a batch file that is in another directory from my Java executable. I have the following code : try { Process p = Runtime.getRuntime().exec("cmd /c start \"C:\\Program Files\\salesforce.com\\Data…
Ricardo
  • 369
  • 3
  • 5
  • 18
10
votes
4 answers

Using non-ASCII characters in a cmd batch file

I'm working on a .bat program, and the program is written in Finnish. The problem is that CMD doesn't know these "special" letters, such as Ä, Ö, Å. Is there a way to make those work? I'd also like it if the user could use those letters too. Part of…
batchguy11
  • 125
  • 1
  • 1
  • 6
10
votes
1 answer

run Matlab in batch mode

It seems to me that there are two ways to run Matlab in batch mode: the first one: unset DISPLAY matlab > matlab.out 2>&1 << EOF plot(1:10) print file exit EOF The second one uses option "-r MATLAB_command": matlab -nojvm -nosplash -r…
Tim
  • 1
  • 141
  • 372
  • 590
10
votes
6 answers

Running a php script with a .bat file

I need to run a php script at midnight every night on my server. On a linux system I'd set up a cron job, but I'm stuck with a windows system. I know I have to set up a task using the windows task scheduler, and that the task will need to run a .bat…
evilscary
  • 2,097
  • 5
  • 23
  • 33
10
votes
4 answers

Comparing Two Folders and its Subfolder batch file

I have two folders that contain all the same files and subfolders, but the conents inside each file may have changed. I want to write a batch file that will search through each file and look for any differences. What's the best tool for what I want…
user2296207
  • 171
  • 1
  • 3
  • 8
10
votes
3 answers

DOS batch: SET variable and ECHO it within (...) block

I had a problem with set not working in a batch file; it took a while to distil the problem; at first I thought it was to do with subroutine calls... The script @echo off setlocal set a=aaa echo a = "%a%" ( set b=bbb echo b = "%b%" ) produces the…
Rhubbarb
  • 4,248
  • 6
  • 36
  • 40