Sei sulla pagina 1di 3

13/12/2015

CMD.exe(CommandShell)|WindowsCMD|SS64.com

Syntax Search…

Search…

StartanewCMDshelland(optionally)runacommand/executableprogram.

CMD [charset] [options] [/C Command]

CMD [charset] [options] [/K Command]

/C

Run Command and then terminate

/K

Run Command and then return to the CMD prompt. This is useful for testing, to examine variables

Command : The command, program or batch script to be run. This can even be several commands separated with '&' (the whole should also be surrounded by "quotes")

/T:fg Sets the foreground/background colours

/A

Output ANSI characters

/U

Output UNICODE characters (UCS­2 le) These options will affect piping or redirecting to a file. Most common text files are ANSI, use these switches when you need to convert the character set.

/D

Ignore registry AutoRun commands HKLM | HKCU \Software\Microsoft\Command Processor\AutoRun

/E:ON Enable CMD Command Extensions (default)

Enable CMD Command Extensions (old switch for compatibility)

/E:OFF Disable CMD Command Extensions

Disable CMD Command Extensions (old switch for compatibility)

/F:ON Enable auto­completion of pathnames entered at the CMD prompt /F:OFF Disable auto­completion of pathnames entered at the CMD prompt (default)

AtthecommandpromptCtrl­DgivesfoldernamecompletionandCtrl­FgivesFile

Thesekey­strokeswilldisplaythefirstmatchingpath.Thereafter,repeatedpressingof

thesamecontrolkeywillcyclethroughthelistofmatchingpaths.PressingSHIFTwith

thecontrolkeywillmovethroughthelistbackwards.

/Q

Turn echo off

/S

Strip " quote characters from command. If command starts with a quote, the first and last quote chars in command will be removed, whether /s is specified or not.

/V:ON Enable delayed environment variable expansion this allows a FOR loop to specify !variable! instead of %variable% expanding the variable at execution time instead of at input time.

Disable delayed environment expansion. Delayed Environment expansion can also be set with SETLOCAL

( SS64 ) CMD.exe Syntax Options /X /Y /V:OFF CMD CMD [ charset ] [

CMD.exe

Syntax

Options

/X

/Y

/V:OFF

CMD

CMD [charset] [options]

andfoldernamecompletion.

13/12/2015

CMD.exe(CommandShell)|WindowsCMD|SS64.com

If/Cor/Kisspecified,thentheremainderofthecommandlineisprocessedasanimmediatecommandinthe

newshell.Multiplecommandsseparatedbythecommandseparator'&'or'&&'areacceptedifsurroundedby

quotes.

FormoredetailsonworkingintheCMDshell:QuickEdit,handingquotesetc,seetheCMDSyntaxpage.

ErrorLevel

CMD/Cwillreturnanerrorlevel,forexampleCMD /c dir Z: wherethedriveZ:doesnotexist,willreturn

%errorlevel%=1tothecallingCMDshell.

LaunchingCMD/batchfilesfromaUNCpath

WhilemostcommandlineutilitiesdofullysupportUNCpaths,theycannotbesetasthecurrentdirectory. LaunchingabatchfilefromaUNCpathwillimplicitlyrunCMD.exewiththatUNCpath,thiswilloftenreturnthe error:pathisaninvalidcurrentdirectorypath.UNCpathsarenotsupported.DefaultingtoWindowsdirectory. Thiscanbedangerousifyourbatchfilemakesanyassumptionsaboutthecurrentdirectory, e.g.ifitincludesthelineDEL *.ico,thatwilldelete.icofilesfromtheWindowsdirectoryinsteadofthefolder wherethebatchfileresides. Ifyouareconfidentthatthebatchfilewon'tbeaffectedbythis,youcansuppresstheerrorinoneoftwoways:

AddaCLScommandasthefirstlineofthebatchscript,oraddtheregistrykeyDisableUNCCheckas

describedinQ156276

Alternativelystartthebatchfilewithpushd "%~dp0"

Thatwillchangedirectorytoyourbatchfilelocation(%0),andforUNCpathsitwillauto­createatemporarydrive

map.

CommandExtensions

MuchofthefunctionalityofCMD.execanbedisabled­thiswillaffectalltheinternalcommands,Command

Extensionsareenabledbydefault.Thiscanbechangedbysettingavalueintheregistry:

HKCU\Software\Microsoft\CommandProcessor\EnableExtensions CommandExtensionscanalsobeturnedonoroffbyrunningCMD /e:onorCMD /e:off orrunSETLOCAL EnableExtensions(SetLocalwilltakeprecedence)

Examples:

RunaprogramandpassaFilenameparameter:

CMD /c write.exe c:\docs\sample.txt

RunaprogramandpassaLongFilename:

CMD /c write.exe "c:\sample documents\sample.txt"

SpacesinProgramPath:

CMD /c ""c:\Program Files\Microsoft Office\Office\Winword.exe""

SpacesinProgramPath+parameters:

CMD /c ""c:\Program Files\demo.cmd"" Parameter1 Param2

SpacesinProgramPath+parameterswithspaces:

CMD /k ""c:\batch files\demo.cmd" "Parameter 1 with space" "Parameter2 with space""

LaunchDemo1andthenLaunchDemo2:

CMD /c ""c:\Program Files\demo1.cmd" & "c:\Program Files\demo2.cmd""

“Thosewhocancommandthemselves,commandothers”‑Hazlitt

Related:

CMDShell­TipsonworkingintheWindowsCMDshell.

EXIT­UsethistocloseaCMDshellandreturn.

CALL­Callonebatchprogramfromanother

START­Runaprogram,commandorbatchfile

13/12/2015

CMD.exe(CommandShell)|WindowsCMD|SS64.com

DOSKEY­Editcommandline,recallcommands CMDInternal­CommandsthatareInternaltotheCMDshell.

Q156276­CmddoesnotsupportUNCnamesasthecurrentdirectory

Powershell:YoucanruntheCMDshellunderPowershell,ExitwillreturnyoutothePSprompt.

Equivalentbashcommand(Linux):bash­runthebashshell(alsocsh,ksh,sh)

RepairWindows Update HavingProblemsUpdating

HavingProblemsUpdating

Windows?FixWindowswith

ReimageRepair

Update HavingProblemsUpdating Windows?FixWindowswith ReimageRepair ©Copyright SS64.com 1999­2015 Somerightsreserved
Update HavingProblemsUpdating Windows?FixWindowswith ReimageRepair ©Copyright SS64.com 1999­2015 Somerightsreserved

©CopyrightSS64.com1999­2015

Somerightsreserved