Questions tagged [cmd]

Command Prompt (executable name cmd.exe) is the Microsoft supplied command line interpreter on OS/2, Windows CE, and all Microsoft Windows operating systems. Use this tag for questions regarding programming scripts or on commands available to run from the Command Prompt. Add tags for which version of Windows, and tags describing the task or issue.

Command Prompt (executable name cmd.exe) is the Microsoft-supplied command-line interpreter on Windows NT-based operating systems (including Windows 2000, XP, Vista, 7, 8, 10, Server 2003, Server 2008, Server 2012 and Server 2016), OS/2 and Windows CE. It is the analog of COMMAND.COM in MS-DOS and Windows 9x (where it is called MS-DOS Prompt) systems, or of the Unix shells used on Unix-like systems.

Include additional tags to identify the version of Windows such as , , , etc.

Resources:

See also:

26386 questions
351
votes
14 answers

Windows shell command to get the full path to the current directory?

Is there a Windows command line command that I can use to get the full path to the current working directory? Also, how can I store this path inside a variable used in a batch file?
user62958
  • 4,669
  • 5
  • 32
  • 35
346
votes
26 answers

Batch script: how to check for admin rights

How do I check if the current batch script has admin rights? I know how to make it call itself with runas but not how to check for admin rights. The only solutions I've seen are crude hack jobs or use external programs. Well, actually I don't care…
flacs
  • 3,913
  • 4
  • 19
  • 20
313
votes
27 answers

Create an empty file on the commandline in windows (like the linux touch command)

On a windows machine I get this error 'touch' is not recognized as an internal or external command, operable program or batch file. I was following these instructions which seem to be linux specific, but on a standard windows commandline it does…
CuriousAboutNode
  • 3,157
  • 2
  • 11
  • 6
313
votes
18 answers

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)?
Keng
  • 52,011
  • 32
  • 81
  • 111
311
votes
14 answers

Logical operators ("and", "or") in DOS batch

How would you implement logical operators in DOS Batch files?
JoelFan
  • 37,465
  • 35
  • 132
  • 205
303
votes
6 answers

How to do something to each file in a directory with a batch script

How do you iterate over each file in a directory with a .bat or .cmd file? For simplicity please provide an answer that just echoes the filename or file path.
Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636
298
votes
8 answers

What encoding/code page is cmd.exe using?

When I open cmd.exe on Windows, what encoding is it using? How can I check which encoding it is currently using? Does it depend on my regional setting or are there any environment variables to check? What happens when you type a file with a certain…
Dan Gøran Lunde
  • 5,148
  • 3
  • 26
  • 24
293
votes
18 answers

What is the proper way to test if a parameter is empty in a batch file?

I need to test if a variable is set or not. I've tried several techniques but they seem to fail whenever %1 is surrounded by quotes such as the case when %1 is "c:\some path with spaces". IF NOT %1 GOTO MyLabel // This is invalid syntax IF "%1" ==…
blak3r
  • 16,066
  • 16
  • 78
  • 98
290
votes
3 answers

What does cmd /C mean?

I can understand cmd but not cmd /c. I was trying to invoke a java program from the current for which I use Runtime.getRuntime().exec("cmd /C java helloworld"); There arises my doubt.
user62835
  • 3,219
  • 3
  • 19
  • 8
286
votes
20 answers

Windows batch: echo without new line

What is the Windows batch equivalent of the Linux shell command echo -n which suppresses the newline at the end of the output? The idea is to write on the same line inside a loop.
gregseth
  • 12,952
  • 15
  • 63
  • 96
281
votes
13 answers

How to create empty text file from a batch file?

Can somebody remember what was the command to create an empty file in MSDOS using BAT file?
m_pGladiator
  • 8,462
  • 7
  • 43
  • 61
268
votes
13 answers

Batch file: Find if substring is in string (not in a file)

In a batch file, I have a string abcdefg. I want to check if bcd is in the string. Unfortunately it seems all of the solutions I'm finding search a file for a substring, not a string for a substring. Is there an easy solution for this?
Ben
  • 54,723
  • 49
  • 178
  • 224
257
votes
11 answers

How do I use spaces in the Command Prompt?

How can I use spaces in the Windows Command Line? cmd /C C:\Program Files (x86)\WinRar\Rar.exe a D:\Hello 2\File.rar D:\Hello 2\*.*
faressoft
  • 19,053
  • 44
  • 104
  • 146
255
votes
13 answers

How do I run a Java program from the command line on Windows?

I'm trying to execute a Java program from the command line in Windows. Here is my code: import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import…
Elizabeth Turner
  • 2,711
  • 3
  • 15
  • 11
250
votes
11 answers

Keep CMD open after BAT file executes

I have a bat file like this: ipconfig That will print out the IP info to the screen, but before the user can read that info CMD closes itself. I believe that CMD assumes the script has finished, so it closes. How do I keep CMD open after the script…
pattyd
  • 5,927
  • 11
  • 38
  • 57