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
5 answers

Is it possible to detect if a batch file is started with CALL command or without?

The problems is that CALL command doubles the caret sign ^ and make double percentage a single one. And in hybrid files this can be a big problem.Or if a bat is not executed with CALL from another bat and you want to warn the user. The…
npocmaka
  • 55,367
  • 18
  • 148
  • 187
10
votes
5 answers

How to wait all batch files to finish before exiting?

I have a main batch file than calls 4 other batch files so we can run in parallel. Example: Main.bat start call batch1.bat start call batch2.bat start call batch3.bat start call batch4.bat exit I want the Main.bat to exit after…
roxsap
  • 137
  • 2
  • 7
10
votes
4 answers

Windows Batch - Pretty Print JSON per Script

I have multiple JSON-files on a server, which can only run batch-scripts or command-line tools. The JSON files all aren't formatted properly, meaning there are no tab-spaces at the beginning of lines. Is there a way, to write a batch-script or run a…
user5417542
  • 3,146
  • 6
  • 29
  • 50
10
votes
2 answers

Set Specific IIS 7 Site with AppCmd?

I have an IIS 7 machine with multiple apps/vdirs on the single default web site. I would like to set two of them with this authentication: anonymous - off impersonation - on forms auth - off windows auth - on I would like to do this with appcmd.exe…
Snowy
  • 5,942
  • 19
  • 65
  • 119
10
votes
1 answer

How can I get return value ( string ) from called Python by BatchFile

I need to have some help. I used python33 on Windows OS. I want result it. Call Python in Batch File. ( python Testing.py %arg1% %arg2% ) python is do return string value. ( return('END') or exit('END') ) and I want set BatchFile Variable ( SET…
Kibum Ko
  • 123
  • 1
  • 1
  • 6
10
votes
6 answers

IF EXIST C:\directory\ goto a else goto b problems windows XP batch files

whenever i run the code below it occurs to me I have made a mistake using the if exist lines, as no matter whether the directory exists or not, it acts as if the line was never there... either that or its not reading the else line. echo off echo …
Ryan Leach
  • 4,262
  • 5
  • 34
  • 71
10
votes
2 answers

How can I find out a files “mime-type(Content-Type?)”? on Windows

Is there a way to find out the MIME-TYPE (or is it called "Content-Type"...) of a file in windows batch/PowerShell?
eldblz
  • 758
  • 3
  • 11
  • 24
10
votes
1 answer

Batch file - Write list of files to variable

I'd like to get a list of all files (including their absolute path) into a variable, separated by spaces. My Google-fu seems to be weak in this regard, because I keep running into issues. I have a base directory stored in %baseDir%, and would like…
erik
  • 3,810
  • 6
  • 32
  • 63
10
votes
2 answers

Umlaut character not accepted via keyboard (codepage 65001, UTF-8) to be read by perl script

Please let me state first that this problem is strictly related to the perl diamond operator accepting input that has been directly typed on the keyboard. Had I talked about the perl diamond operator accepting input that that has been piped or…
user2288349
  • 267
  • 2
  • 12
10
votes
1 answer

CMD: File tasks, open directory and select file

I want to open a folder and automatically select a file from the command line: >> explorer C:\Windows\system32\selected_file.txt Once Windows Explorer has opened C:\Windows\system32 I want selected_file.txt to be highlighted automatically. Is that…
Thom
  • 591
  • 4
  • 12
  • 30
10
votes
3 answers

Reading a value from a file in a windows batch script

I'm trying to read a value from a file and use it in a subsequent command. I have a file called AppServer.pid which contains the process id of my app server (just the number, it's not a properties file or anything like that). The app server is…
Harry Lime
  • 29,476
  • 4
  • 31
  • 37
10
votes
1 answer

Open the Android Signing Wizard from a batch file

How can I display the dialog appearing when clicking in Android Studio (IntelliJ) on Build->Generate Signed APK... from a batch file? I do not want to have a command-line interface for inserting the passwords, I want to display the colorful…
PhilLab
  • 4,777
  • 1
  • 25
  • 77
10
votes
3 answers

How do I kill a specific process running in the background from the command prompt?

Assuming this is a Windows 7 machine - and we're talking about batch scripts on the Windows command line. Imagine I want to start and stop two different processes running in the background, and run things whilst they running in the background. For…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
10
votes
2 answers

Add batch file to PATH

I'm trying to run a .bat file globally by adding the directory which contains it to PATH. This obviously works for exe files but is there a way to run .bat files this way?
rykeeboy
  • 645
  • 2
  • 8
  • 22
10
votes
3 answers

How to dir without showing extension (batch)

For example, I have the folder d:\temp\ and four word document files in it (.doc) I know that dir /b "d:\temp" will give me File1.doc File2.doc File3.doc File4.doc But how can I do it so that there are only file names without…
z1lent
  • 147
  • 1
  • 1
  • 10