Command Prompt (executable name cmd.exe) is the Microsoft supplied command line interpreter on OS/2, Windows CE, and Windows NT operating systems (including Windows 2000, XP, Vista, 7, Server 2003, and Server 2008).
188
votes
15answers
297k views
Batch file to delete files older than N days
I am looking for a way to delete all files older than 7 days in an MS-DOS batch file. I've searched around the web, and found some examples with hundreds of lines of code, and others that required ...
178
votes
8answers
303k views
How to Pass Command Line Parameters in Batch File
I needed to pass id and password to a cmd (or bat) file at the time of running rather than hardcoding them into the file.
Here's how I do it.
@echo off
fake-command /u %1 /p %2
Here's what the ...
176
votes
11answers
94k views
Windows batch files: .bat vs .cmd?
As I understand it, .bat is the old 16-bit naming convention, and .cmd is for 32-bit Windows, i.e., starting with NT. But I continue to see .bat files everywhere, and they seem to work exactly the ...
167
votes
4answers
120k views
How do I get the application exit code from a Windows command line?
I am running a program and want to see what its return code is (since it returns different codes based on different errors).
I know in Bash I can do this by running
echo $?
What do I do when ...
150
votes
2answers
65k views
Long commands split over multiple lines in Vista/DOS batch (.bat) file
How do I make long commands go over multiple lines in a Vista/DOS batch file?
129
votes
6answers
69k views
What does %~dp0 mean, and how does it work?
I find %~dp0 very useful, and I use it a lot to make my batch files more portable.
But the label itself seems very cryptic to me... what is the ~ doing? does dp mean drive and path? does the 0 refer ...
96
votes
10answers
89k views
How to run multiple bat files within a bat file
Im trying to get my commit-build.bat to exceute other bat files as part of our build process.
content of commit-build.bat:
"msbuild.bat"
"unit-tests.bat"
"deploy.bat"
Seems simple enough? But the ...
82
votes
11answers
77k views
Is there a command to refresh environment variables from the command prompt in Windows?
If I modify or add an environment variable I have to restart the command prompt (minor inconvenience). Is there a command I could execute that would do this without restarting CMD?
72
votes
10answers
161k views
Stop and Start a service via batch or cmd file?
How can I script a bat or cmd to stop and start a service reliably with error checking (or let me know that it wasn't successful for whatever reason)?
65
votes
18answers
74k views
Displaying Windows command prompt output and redirecting it to a file
How can I run a command-line application in the Windows command prompt and have the output both displayed and redirected to a file at the same time?
If, for example, I were to run the command dir ...
63
votes
11answers
77k views
batch scripting iterating over files in a directory
How could I iterate over each file in a directory using for? And how could I tell if a certain entry is a directory or if it's just a file?
62
votes
3answers
71k views
How to get folder path from file path with CMD
I need path to the folder that contains cmd file.
With %0 I can get file name. But how to get folder name?
c:\temp\test.cmd >> test.cmd
P.S. My current directory != folder of the script.
52
votes
7answers
21k views
Why git can't remember my passphrase under Windows
I have just start using git and i can't get it to remember my passphrase I'm using cmd.exe elevated and my git host is github and i have create a ssh key like that guide on github
but i still get
...
52
votes
3answers
31k views
Redirect stdout and stderr to a single file in DOS
I'm trying to redirect all output (stdout + stderr) of a dos command to a single file:
C:\>dir 1> a.txt 2> a.txt
The process cannot access the file because it is being used by another ...
52
votes
6answers
74k views
Executing multiple commands from a Windows cmd script
I'm trying to write a Windows cmd script to perform several tasks in series.
However, it always stops after the first command in the script.
The command it stops after is a maven build (not sure if ...