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:

50401 questions
8
votes
3 answers

What exactly is this batch file supposed to do?

What does this do in a .bat file? Is it some sort of assembly language or what? @debug <%0 >nul e100 48 e6 61 be 3f 01 31 db 8a 1c 80 fb ff 74 f4 81 e110 c3 d0 00 b0 b6 e6 43 31 d2 66 b8 dd 34 12 00 66 e120 f7 f3 e6 42 88 e0 e6 42…
Peter Rogers
8
votes
6 answers

Passing a multi-line string as an argument to a script in Windows

I have a simple python script like so: import sys lines = sys.argv[1] for line in lines.splitlines(): print line I want to call it from the command line (or a .bat file) but the first argument may (and probably will) be a string with multiple…
Zack The Human
  • 8,052
  • 6
  • 37
  • 59
8
votes
4 answers

How can I read multiple files from multiple directories into R for processing?

I am running a simulation study and need to process and save the results from several text files. I have the data organized in such a way where there are sub directories and within each sub directory, I need to process and get individual results for…
Stefanie
  • 81
  • 1
  • 1
  • 2
8
votes
5 answers

Check if computer is plugged into AC power in batch file

How can I check if computer is plugged into AC power in a batch file in windows 7, like on_ac_power does in linux?
Jakob Weisblat
  • 6,663
  • 8
  • 31
  • 61
8
votes
1 answer

JDBC batch insert being SLOW! I mean, REALLY SLOW?

Here's the deal: I create a connection conn using the DriverManager I set conn.autoCommit(false); Then I have PreparedStatement pStat = conn.prepareStatement(insert_string_with_parameter); I set several parameters with pStat.set... then I add the…
Marsellus Wallace
  • 15,881
  • 21
  • 79
  • 143
8
votes
3 answers

Merge 2 txt files in a single tab delimited file in batch

I'm stuck with this : I need to merge two text files in a single tab delimited text file, on a batch script. ex : file1: qwer tyui asdf file2: 1345 6876 8796 file3: qwer 1345 tyui 6876 asdf 8796 All I need in fact, is a equivalent to…
user767990
  • 115
  • 2
  • 6
8
votes
2 answers

Arrow keys trigger "pause" twice in Windows batch files

try this in an otherwise empty .bat file: @echo off echo Try space and arrow-down pause echo 1 pause echo 2 pause echo 3 pause echo 4 pause echo 5 Why does any of the arrow keys trigger two consecutive pauses, while a space or a letter only…
bers
  • 2,809
  • 1
  • 19
  • 39
8
votes
6 answers

Opening multiple PDF documents using batch file

I am trying to open several PDF documents using a simple batch file: ECHO OFF CLS cd Program Files\Adobe\Reader 9.0\Reader Acrord32.exe C:\Users\BW1.pdf Acrord32.exe C:\Users\BW2.pdf Acrord32.exe C:\Users\BW3.pdf Acrord32.exe…
Dmitri
8
votes
4 answers

Find out if file is older than 4 hours in Batch file

Quite simply, how would I find out if a specific file in a folder is older than X hours? The file name and location will always be the same. Thanks
user270370
  • 141
  • 1
  • 2
  • 8
8
votes
4 answers

Django design pattern for web analytics screens that take a really long time to calculate

I have an "analytics dashboard" screen that is visible to my django web applications users that takes a really long time to calculate. It's one of these screens that goes through every single transaction in the database for a user and gives them…
MikeN
  • 39,649
  • 47
  • 142
  • 222
8
votes
4 answers

Simple way to backup event log on Windows Server

Is it possibile to create a simple way to backup the event log, with such as a batch file or a simple app ? I need to make it working on a customer's site, where the reference is an non-expert user. Thanks
dancerjude
  • 111
  • 1
  • 1
  • 8
8
votes
4 answers

Do MS-DOS built-in commands return an error\exit code?

I have not found a way to get the error code, if returned, of rmdir. It seems like the MS-DOS internal commands do not return an error code. Can someone confirm that? How does a script that uses these commands know if the commands succeed or fail…
Duat Le
  • 3,576
  • 2
  • 17
  • 18
8
votes
3 answers

Memory leak in batch for loop?

I am writing a batch script that goes through every file in a directory looking for code files and modifies them in some way. After I finished that task I tried to run it on a large directory with about 6,000 files. About 40 minutes in the script…
Maynza
  • 708
  • 5
  • 17
8
votes
11 answers

Creating a batch file, for simple javac and java command execution

It is a really simple thing but I cannot get my head around it. I have looked at plenty of StackOverFlow post and as well as on internet. My goal is to create a .bat which will open cmd and execute my Main.java into command prompt. Easy isn't it,…
TeaCupApp
  • 11,055
  • 16
  • 65
  • 143
8
votes
2 answers

How do I pass arguments to shell script?

I have a batch file like this: java temptable %1 %2 I need the equivalent shell script for the above. I will pass the arguments to the shell script and that should be passed to temptable.
abc
1 2 3
99
100