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

Run .bat in Linux environment

Is there any way to run .bat file in Linux environment? I have a couple of .bat files, the purpose of them is to call mvn install:install-file scripts. Thus nothing OS dependent is in the scripts. Thank you,
Sqeezer
  • 1,267
  • 2
  • 14
  • 23
10
votes
3 answers

Parsing string in batch file

I have the following string: MyProject/Architecture=32bit,BuildType=Debug,OS=winpc I would like to be able to grab the values 32bit, Debug, and winpc and store them in variables named Architecture, BuildType, and OS to reference later in the batch…
user869525
  • 769
  • 2
  • 12
  • 21
10
votes
5 answers

CMD nested double quotes in argument

I am having problems with passing arguments to a batch function with nested double quotes. Here is an example of a batch file: @SET path_with_space="c:\test\filenamewith space.txt" @CALL :FUNCTION blaat1, "blaat2 %path_with_space%" @GOTO…
Davor Josipovic
  • 5,296
  • 1
  • 39
  • 57
10
votes
4 answers

CLS (clear) a single line?

Is there any way to CLS a single line of output? I don't believe there are any switches for CLS, so maybe a better question would be: Is there any way to retain all previous output for re-use? or capture currently displayed output (like you can…
mythofechelon
  • 3,692
  • 11
  • 37
  • 48
10
votes
1 answer

Running variable string as command in batch scripting

EDIT: There was nothing wrong with the code below. The error was coming from elsewhere. The command variable is the command I want to execute. The name variable is pulling a list of computer names. When I echo !command! it returns the value I…
spassen
  • 1,550
  • 8
  • 20
  • 32
10
votes
6 answers

How can I make a batch file to act like a simple grep using Perl?

I already know the obvious answer to this question: "just download ". However, I work in an environment with strict controls by the local IT staff as to what we're allowed to have on our…
Ogre Psalm33
  • 21,366
  • 16
  • 74
  • 92
10
votes
3 answers

Is it possible to batch updates in Sequel?

Is it possible to make many updates in a single call using Sequel? For instance, making about 200 updates could take several minutes on my server, but if I forge a single SQL query it runs in a matter of seconds. I wonder if Sequel could be used to…
RooSoft
  • 1,481
  • 2
  • 17
  • 32
10
votes
3 answers

Batch (.bat): get the name of the first script, not the current one

I have first.bat and second.bat. first.bat is: call second.bat Second is: echo %~n0 (displays filename of the executing batch) The output is Second.bat, but I want it to display the caller filename, not it's own. Is this possible?
9
votes
5 answers

Is there Uninstall a program batch for windows?

I have several programs I want to uninstall from my computer (Windows 7 64bit). Is there a batch\script that can help me do it? or I need to do it one by one from Control Panel? If there isn't for Windows 7, is there something like this in…
Dor Cohen
  • 16,769
  • 23
  • 93
  • 161
9
votes
2 answers

JDBC batch query for high performance

I want to do batch query DB for high performance, example sql to query based on different customer_id: select order_id, cost from customer c join order o using(id) where c.id = ... order by I'm not sure how to do it using JDBC…
superche
  • 753
  • 3
  • 9
  • 21
9
votes
6 answers

restore the previous echo status

In a DOS Batch File subroutine, how can I turn off echo within the subroutine, but before returning, put it back to what it was before (either on or off)? For example, if there was a command called echo restore, I would use it like this: echo on ...…
JoelFan
  • 37,465
  • 35
  • 132
  • 205
9
votes
2 answers

How to to terminate a windows batch file from within a 'call'ed routine?

I've got a windows batch file, with a few sub-routines in it something like this: call :a goto :eof :a call :b goto :eof :b :: How do I directly exit here from here? goto :eof I'm running this in a cmd window on Vista. If I detect an error…
Scott Langham
  • 58,735
  • 39
  • 131
  • 204
9
votes
2 answers

bat function to find a file in folder and subfolders and do something with it.

I need to find all files with specific filename(for example main.css) in folder and all subfolders and then do something with it(eg. rename, move, delete, add text line, etc)
Davinel
  • 940
  • 4
  • 10
  • 20
9
votes
1 answer

Is It Possible to Create CSV File with Multiple Tabs in Command Prompt?

I'm looking to create a .csv file that can be opened in Excel that displays 2 tabs. However, the catch is that the script that I write has to be in a batch file (command prompt). I've seen a few ways to do this online, but they're all JAVA programs.…
sanshou0813
  • 101
  • 1
  • 1
  • 3
9
votes
4 answers

batch to copy files with xcopy

I have checked some examples on internet but I can't get my (first) batch file to work. I would like to copy automatically my file from a folder to another one but nothing happen. @echo off xcopy "C:\source\" "C:\target\" /c /d /i /y exit Could you…
remyremy
  • 3,548
  • 3
  • 39
  • 56