BAT file: Open new cmd window and execute a command in there

后端 未结 8 2131
囚心锁ツ
囚心锁ツ 2020-11-29 15:52

I\'m trying to open a new command window in a BAT file:

start %windir%\\system32\\cmd.exe

After it opens, I\'d like to execute a BAT comman

8条回答
  •  萌比男神i
    2020-11-29 16:18

    Use the following in your batch file:

    start cmd.exe /k "more-batch-commands-here"
    

    or

    start cmd.exe /c "more-batch-commands-here"
    

    /c Carries out the command specified by string and then terminates
    /k Carries out the command specified by string but remains

    Consult the cmd.exe documentation using cmd /? for more details.

    The proper formating of the command string gets a little more complicated with spaces in the arguments. See the examples below. Note the use of nested double quotes in some examples.

    Examples:

    Run a program and pass a filename parameter:
    CMD /c write.exe c:\docs\sample.txt

    Run a program and pass a long filename:
    CMD /c write.exe "c:\sample documents\sample.txt"

    Spaces in program path:
    CMD /c ""c:\Program Files\Microsoft Office\Office\Winword.exe""

    Spaces in program path + parameters:
    CMD /c ""c:\Program Files\demo.cmd"" Parameter1 Param2
    CMD /k ""c:\batch files\demo.cmd" "Parameter 1 with space" "Parameter2 with space""

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

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

提交回复
热议问题