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
9
votes
2 answers

Windows batch file && operator

In bash I can write this: #!/bin/sh ant debug && adb install -r bin/Rocher-debug.apk But I have a similar windows batch file, and currently it does this: ant debug adb install -r bin/Rocher-debug.apk So, if "ant debug" fails, it will still run…
fieldtensor
  • 3,972
  • 4
  • 27
  • 43
9
votes
4 answers

Batch script to zip all the files without the parent folder

I wanted to create a batch file that can make a zip file from a folder that I put in the script. Here's my script: @REM ------- BEGIN xpi.bat ---------------- @setlocal @echo off set path="C:\Program Files\WinRAR\";%path% winrar.exe a -afzip -m5…
wahyueka31
  • 664
  • 2
  • 8
  • 18
9
votes
2 answers

Scala scripts in Windows batch files

In Programming in Scala, it gives a description on how to run Scala scripts from batch files (link). For Windows ::#! @echo off call scala %0 %* goto :eof ::!# I'm having a problem googling ::#!. What does this mean? I know :: denotes a…
Luigi Plinge
  • 50,650
  • 20
  • 113
  • 180
9
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,586
  • 2
  • 19
  • 18
9
votes
2 answers

Problem of empty variable using set in Windows Batch

set var=%1 echo var set command="" IF var==true ( set command=dir ) IF var==false ( set command=dir /a ) echo %command% %command% So, if I run this script by typing in C:\>test true the echo %command% always prints "". Any idea?
zs2020
  • 53,766
  • 29
  • 154
  • 219
9
votes
3 answers

Help in writing a batch script to parse CSV file and output a text file

I am struggling to write a batch script which can read a CSV file such as below Name:, City:, Country: Mark, London, UK Ben, Paris, France Tom, Athens, Greece There will be a heading row in the CSV file. It should output to a text file as…
Benny
  • 639
  • 3
  • 11
  • 25
9
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
  • 748
  • 5
  • 18
9
votes
4 answers

Hibernate Batch Insert. Would it ever use one insert instead of multiple inserts?

I've been looking around trying to determine some Hibernate behavior that I'm unsure about. In a scenario where Hibernate batching is properly set up, will it only ever use multiple insert statements when a batch is sent? Is it not possible to use a…
AHungerArtist
  • 9,332
  • 17
  • 73
  • 109
9
votes
5 answers

BAT script to copy files from Windows to remote Linux systems

Is there anyway to copy files from Windows machine to a remote Linux machine with a DOS command/other command-line tool (by specifying username and password in the command). I normally do this using WinSCP and would like to write a script (BAT) to…
softwarematter
  • 28,015
  • 64
  • 169
  • 263
9
votes
3 answers

How to run one exe by passing dynamic parameters using single bat file

I have an requirement to run one EXE. It will take 7 parameters out of which one parameter is dynamic. Could some one help me how to run the EXE by passing dynamic parameters using bat file. Thanks Chaitanya
Chaitanya
  • 91
  • 1
  • 1
  • 2
9
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
9
votes
1 answer

sqlcmd - How to get around column length limit without empty spaces?

I'm trying to use sqlcmd on a windows machine running SQL Server 2005 to write a query to a csv file. The command line options we typically use are: -l 60 -t 300 -r 1 -b -W -h -1 However, the columns are getting truncated at 256 bytes. In an…
Tony Trozzo
  • 1,231
  • 6
  • 20
  • 34
9
votes
2 answers

Is there the "Windows Batch file" emulator/interpreter for UNIX?

Can I run the batch file on UNIX? (Linux / Mac OS X) I am looking for the interpreter to run the Windows Batch file on UNIX, like 'bash' for bash script, 'csh' for csh script, so 'XXX' for windows batch file. I am developing a Java application.…
kaorukobo
  • 2,223
  • 2
  • 22
  • 29
9
votes
1 answer

windows batch file: calling executable in another directory

This seems like something simple, but I don't seem to be able to get it. I have a directory called "test" with an executable hello.exe that basically prints "hello" onto the screen. I want to execute this program from the current directory using…
MxLDevs
  • 19,048
  • 36
  • 123
  • 194
9
votes
1 answer

Jenkins Pipeline bat multiple lines

According to the docs, one can have multiple lines in the script paramater of bat. However, I've tried the following in my stage steps and only the first line gets executed. Declarative pipeline: ... bat """ c:\\path\\to\\conda activate my_env …
Griffin
  • 13,184
  • 4
  • 29
  • 43
1 2 3
99
100