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.
            Asked
            
        
        
            Active
            
        
            Viewed 7.9e+01k times
        
    290
            
            
        - 
                    10To Moderators, is there a provision to move this to appropriate portal/subsidiary of stack overflow. That way this item will not be closed and users will be able to contribute more? I guess this should go to something similar to super user? – digitally_inspired Jul 25 '18 at 16:14
 - 
                    2I find it a perfectly valid question for SO. – Andrew Truckle Nov 29 '22 at 09:17
 
3 Answers
332
            
            
        The part you should be interested in is the /? part, which should solve most other questions you have with the tool.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\>cmd /?
Starts a new instance of the Windows XP command interpreter
CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
    [[/S] [/C | /K] string]
/C      Carries out the command specified by string and then terminates
/K      Carries out the command specified by string but remains
/S      Modifies the treatment of string after /C or /K (see below)
/Q      Turns echo off
/D      Disable execution of AutoRun commands from registry (see below)
/A      Causes the output of internal commands to a pipe or file to be ANSI
/U      Causes the output of internal commands to a pipe or file to be
        Unicode
/T:fg   Sets the foreground/background colors (see COLOR /? for more info)
/E:ON   Enable command extensions (see below)
/E:OFF  Disable command extensions (see below)
/F:ON   Enable file and directory name completion characters (see below)
/F:OFF  Disable file and directory name completion characters (see below)
/V:ON   Enable delayed environment variable expansion using ! as the
        delimiter. For example, /V:ON would allow !var! to expand the
        variable var at execution time.  The var syntax expands variables
        at input time, which is quite a different thing when inside of a FOR
        loop.
/V:OFF  Disable delayed environment expansion.
        Blorgbeard
        
- 101,031
 - 48
 - 228
 - 272
 
        guyumu
        
- 3,457
 - 2
 - 19
 - 18
 
- 
                    5there's also a command to "pause" the cmd window after output: "cmd /c file_name & PAUSE" it is bit different from cmd /k – GorvGoyl Sep 05 '15 at 19:34
 - 
                    what if a given command is kind of a server that starts it's own loop? should we use /C or /K? – redpix_ Mar 27 '17 at 20:21
 - 
                    While executing command in C# via 'Process' is using /C mandatory in Windows 7 or Windows Server 2008 R2 operating system? – Dinesh Kumar P Jun 12 '17 at 11:14
 - 
                    1I came here becasue its not behaving as described. Im runnig from git bash and cmd /c "dir" or any command will just leave me in cmd prompt without executing the ocmmand. – Brad Oct 23 '20 at 22:44
 - 
                    
 
132
            
            
        /C Carries out the command specified by the string and then terminates.
You can get all the cmd command line switches by typing cmd /?.
        T30
        
- 11,422
 - 7
 - 53
 - 57
 
        Simon Temlett
        
- 2,397
 - 2
 - 17
 - 17
 
- 
                    13But why would one want to? Why not just call the command directly, like "java helloworld" – Mike Sadler Apr 11 '19 at 11:04
 - 
                    4because you might not be in CMD but you just wan to use cmd to execute a command for you. eg I am running a bash script and want it to execute a command that cmd can do but bash can not. – Brad Oct 23 '20 at 22:58
 
29
            
            
        CMD.exe
Start a new CMD shell
Syntax
      CMD [charset] [options] [My_Command] 
Options       
**/C     Carries out My_Command and then
terminates**
From the help.
        phuclv
        
- 37,963
 - 15
 - 156
 - 475
 
        Andrea Ambu
        
- 38,188
 - 14
 - 54
 - 77