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

Download remote file into memory via pure batch

In my batch script, I am trying to download and execute a powershell script remotely. Here is the url: https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1 I want to download the file into memory (without touching disk), for…
HaxAddict1337
  • 733
  • 1
  • 2
  • 17
8
votes
2 answers

Windows Batch: Set Variables from Text File

Im currently looking for a method to set variables in a windows batch file from linkes in txt document. So for example, if the text file reads: http://website1.com http://website2.com http://website3.com I can hopefully output them to variables in…
Dustin
  • 5,457
  • 18
  • 53
  • 82
8
votes
3 answers

How to properly quote file path with SCHTASKS

I'm writing a small app that generates the contents of a batch file, using SCHTASKS to create scheduled tasks. However, I simply cannot get the file path working correctly. I need another set of eyes. SCHTASKS /CREATE /TN "TASK1" /TR…
Ducain
  • 1,521
  • 3
  • 17
  • 27
8
votes
6 answers

How to include pipe character in an argument to a batch file from a bash script?

I have a shell script that I want to execute this line: qtvars.bat vsstart "qt.sln" /BUILD "Debug|Win32" This works fine (though I had to modify qtvars.bat, but that's beside the point). The problem is that I want the command to execute to be in a…
Owen
  • 6,853
  • 8
  • 36
  • 50
8
votes
1 answer

Why would C# ProcessStartInfoRedirectStandardOutput cause xcopy process to fail

This is a bit of a pain because I now don't have the code in front of me, but I'll try to explain. I have a simple C# application that kicks off a Ruby script (it does a couple of other things, so it generates a batch file and executes that). I am…
Lee Winder
  • 797
  • 10
  • 34
8
votes
2 answers

How to execute a bat file from a classic asp page on the server

I have a simple bat file that runs an access macro when executed, i need to know how to execute this bat file from a asp page, i have given all the permissions to the iusr_machinename for that particular folder containing the script file and the asp…
Vamsi
  • 4,119
  • 7
  • 46
  • 73
8
votes
7 answers

"Bring to front" for Windows XP command shell

Is there a command I can put into a Windows XP .bat file to bring the command shell to the front?
Lauren Samuels
  • 2,049
  • 3
  • 17
  • 19
8
votes
3 answers

Windows BAT : test if a specific file is empty

I would like to check if a specific file is empty in a windows .bat file. Here is my non working script : set dir="C:\test" set file="%dir%\fff.txt" cd %dir% if %file%%~zi == 0 exit ftp -s:"%dir%\ftp.action" exit Could you help me debug this…
Réjôme
  • 1,454
  • 3
  • 14
  • 25
8
votes
5 answers

Last token in batch variable

In a batch file, how can I get the last token in a variable regardless of whether it is a number or a word and regardless of how many tokens/words there are in the variable. I will be passing an argument into the batch file like…
Eli
  • 678
  • 1
  • 6
  • 12
8
votes
2 answers

PowerShell loop range with steps

I'm trying to move from BATCH into PowerShell and I am trying to convert my own scripts. My problem is with ranges in loop: my original BATCH script was like for /L %%U in (123,2,323) do ECHO %%U and will print 123 125 127 ... with Powershell…
Lila
  • 419
  • 3
  • 13
8
votes
4 answers

Escaping a quote in findstr search string

How can I properly escape a quote in a search string when using findstr.exe? Example: findstr /misc:"namespace=\"" *.cs > ns.txt This outputs to the console, instead of to the file I specified. I am doing this directly on the command line, not…
Merlyn Morgan-Graham
  • 54,918
  • 14
  • 119
  • 174
8
votes
5 answers

Good alternative to Windows batch scripts?

What are some good alternatives to Windows batch scripts? We have a number of them and they are very "clunky" to work with. As our group is familiar with Java is Groovy a good option? A lot of our scripts are used to prep dev databases so they…
Marcus Leon
  • 50,921
  • 112
  • 279
  • 413
8
votes
5 answers

refresh desktop using batch

I need to refresh the desktop ussing batch is this possible? I have found the following VBscript that refreshes the containing window however, the desktop needs to be refreahed and its not the containing window anyways around this? Set WSHShell =…
philip
  • 325
  • 4
  • 5
  • 8
8
votes
6 answers

make a windows 7 machine crash on BSOD

I'm trying to write a windows debug utility and I would need to automatically crash a Windows machine and make a Blue Screen Of Death appear. I can obviously kill the csrss.exe process from the task manager, but the command TASKKILL /F /IM…
TheSENDER
  • 175
  • 1
  • 1
  • 3
8
votes
2 answers

default value of Set /p in batch script

Is there a way to present a default value in a Set /p statement in a Windows batch script? For example, something like this: Set /p MyVar=My Default Value Echo $MyVar$ If the user presses Enter without typing anything else, then MyVar gets that…
Conrad S.
  • 574
  • 2
  • 7
  • 17
1 2 3
99
100