Sei sulla pagina 1di 3

13/12/2015

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

(SS64)

CMD

Syntax

Search

CMD.exe
StartanewCMDshelland(optionally)runacommand/executableprogram.
Syntax
CMD[charset][options]
CMD[charset][options][/CCommand]
CMD[charset][options][/KCommand]
Options
/CRunCommandandthenterminate
/KRunCommandandthenreturntotheCMDprompt.
Thisisusefulfortesting,toexaminevariables
Command:Thecommand,programorbatchscripttoberun.
Thiscanevenbeseveralcommandsseparatedwith'&'
(thewholeshouldalsobesurroundedby"quotes")
/T:fgSetstheforeground/backgroundcolours

/AOutputANSIcharacters
/UOutputUNICODEcharacters(UCS2le)
Theseoptionswillaffectpipingorredirectingtoafile.
MostcommontextfilesareANSI,usetheseswitches
whenyouneedtoconvertthecharacterset.
/DIgnoreregistryAutoRuncommands
HKLM|HKCU\Software\Microsoft\CommandProcessor\AutoRun
/E:ONEnableCMDCommandExtensions(default)
/XEnableCMDCommandExtensions(oldswitchforcompatibility)
/E:OFFDisableCMDCommandExtensions
/YDisableCMDCommandExtensions(oldswitchforcompatibility)
/F:ONEnableautocompletionofpathnamesenteredattheCMDprompt
/F:OFFDisableautocompletionofpathnamesenteredattheCMDprompt(default)
AtthecommandpromptCtrlDgivesfoldernamecompletionandCtrlFgivesFile
andfoldernamecompletion.
Thesekeystrokeswilldisplaythefirstmatchingpath.Thereafter,repeatedpressingof
thesamecontrolkeywillcyclethroughthelistofmatchingpaths.PressingSHIFTwith
thecontrolkeywillmovethroughthelistbackwards.
/QTurnechooff
/SStrip"quotecharactersfromcommand.
Ifcommandstartswithaquote,thefirstandlastquotecharsincommand
willberemoved,whether/sisspecifiedornot.
/V:ONEnabledelayedenvironmentvariableexpansion
thisallowsaFORlooptospecify!variable!insteadof%variable%
expandingthevariableatexecutiontimeinsteadofatinputtime.

/V:OFF
Disabledelayedenvironmentexpansion.
DelayedEnvironmentexpansioncanalsobesetwithSETLOCAL
http://ss64.com/nt/cmd.html

1/3

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/cdirZ: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),andforUNCpathsitwillautocreateatemporarydrive
map.

CommandExtensions
MuchofthefunctionalityofCMD.execanbedisabledthiswillaffectalltheinternalcommands,Command
Extensionsareenabledbydefault.Thiscanbechangedbysettingavalueintheregistry:
HKCU\Software\Microsoft\CommandProcessor\EnableExtensions
CommandExtensionscanalsobeturnedonoroffbyrunningCMD/e:onorCMD/e:off
orrunSETLOCALEnableExtensions(SetLocalwilltakeprecedence)
Examples:
RunaprogramandpassaFilenameparameter:
CMD/cwrite.exec:\docs\sample.txt
RunaprogramandpassaLongFilename:
CMD/cwrite.exe"c:\sampledocuments\sample.txt"
SpacesinProgramPath:
CMD/c""c:\ProgramFiles\MicrosoftOffice\Office\Winword.exe""
SpacesinProgramPath+parameters:
CMD/c""c:\ProgramFiles\demo.cmd""Parameter1Param2
SpacesinProgramPath+parameterswithspaces:
CMD/k""c:\batchfiles\demo.cmd""Parameter1withspace""Parameter2with
space""
LaunchDemo1andthenLaunchDemo2:
CMD/c""c:\ProgramFiles\demo1.cmd"&"c:\ProgramFiles\demo2.cmd""
Thosewhocancommandthemselves,commandothersHazlitt
Related:
CMDShellTipsonworkingintheWindowsCMDshell.
EXITUsethistocloseaCMDshellandreturn.
CALLCallonebatchprogramfromanother
STARTRunaprogram,commandorbatchfile
http://ss64.com/nt/cmd.html

2/3

13/12/2015

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

DOSKEYEditcommandline,recallcommands
CMDInternalCommandsthatareInternaltotheCMDshell.
Q156276CmddoesnotsupportUNCnamesasthecurrentdirectory
Powershell:YoucanruntheCMDshellunderPowershell,ExitwillreturnyoutothePSprompt.
Equivalentbashcommand(Linux):bashrunthebashshell(alsocsh,ksh,sh)

RepairWindows
Update
HavingProblemsUpdating
Windows?FixWindowswith
ReimageRepair

CopyrightSS64.com19992015
Somerightsreserved

http://ss64.com/nt/cmd.html

3/3

Potrebbero piacerti anche