127

I am in the process of setting up CruiseControl.NET. The problem I am having is that I am running CC as a console application and when my build completes successfully and executes (using exec) it launches it within the CruiseControl DOS prompt. I am just using simple batch files to launch my app but having it run within the same prompt as CC is causing CC to think the build continues as long as my app runs.

Are there command line parameters to cmd.exe that will spawn another separate prompt window?

seldon
  • 977
  • 2
  • 8
  • 20
Mark Stahler
  • 4,186
  • 6
  • 29
  • 29
  • 1
    cmd.exe is a CUI shell, not a GUI. It doesn't create windows. It uses a console window that's created and managed by an instance of conhost.exe, the console host process. If a CUI program is started normally, initialization code in the base client DLL (kernel32.dll or kernelbase.dll) inherits the parent's console, if any, or allocates a new console, unless it's started with the creation flag `DETACHED_PROCESS` (i.e. no console). If it's started with the creation flag `CREATE_NEW_CONSOLE` (as CMD's `start` uses), the base DLL always allocates a new console instead of inheriting the parent's. – Eryk Sun Jun 09 '18 at 15:05

11 Answers11

238

I think this works:

start cmd.exe
KristofMols
  • 3,487
  • 2
  • 38
  • 48
e.James
  • 116,942
  • 41
  • 177
  • 214
77

Here is the code you need:

start cmd.exe @cmd /k "Command"
Pang
  • 9,564
  • 146
  • 81
  • 122
xsukax
  • 901
  • 6
  • 3
  • 12
    What is the `@cmd` doing? Is there some documentation for it? – michas Jul 19 '14 at 19:41
  • 1
    `@` supresses the direct output which normally would show up in the prompt but the command will still be executed. – Thielicious Sep 28 '16 at 18:42
  • I used this, it works but if try to kill the running program by keyboard interrupt ctrl+c, running program does not stop. It only stops when you close the newly opened command prompt window. – Sachin G. Apr 12 '18 at 07:43
  • Doesn't work for multi-line commands using `^`. :( Any way to deal with this? – user2173353 Mar 14 '19 at 12:41
  • `@cmd` appears to be redundant here. Exactly the same bahviour without it. I'm assuming `cmd.exe` silents ignores it as it's an invalid option. You can replace `@cmd` with (almost) any old junk and you'll see the same behaviour. – Jimadine Feb 24 '22 at 12:41
45

Simply type start in the command prompt:

start

This will open up new cmd windows.

Pang
  • 9,564
  • 146
  • 81
  • 122
Esterlinkof
  • 1,444
  • 3
  • 22
  • 27
22
start cmd.exe 

opens a separate window

start file.cmd 

opens the batch file and executes it in another command prompt

Community
  • 1
  • 1
BlackMael
  • 3,198
  • 5
  • 25
  • 42
6

You can just type these 3 commands from command prompt:

  1. start

  2. start cmd

  3. start cmd.exe

Pang
  • 9,564
  • 146
  • 81
  • 122
Jagadeesh HN
  • 59
  • 1
  • 2
4

simple write in your bat file

@cmd

or

@cmd /k "command1&command2"
Luke
  • 11,426
  • 43
  • 60
  • 69
bajie
  • 187
  • 2
  • 7
  • 4
    Thanks for the `&` to execute multiple commands in the new prompt. I like to add `exit` so it closes the prompt when the command have finished running. – Sylhare Aug 28 '17 at 15:32
3
START "notepad.exe"
echo Will launch the notepad.exe application
PAUSE

To make any cmd file type, all you have to do is save the contents as .bat, i.e.

@echo
TITLE example.bat
PAUSE
taskkill/IM cmd.exe

Make that into an "example.bat" file, save it, then open it and run.

Pang
  • 9,564
  • 146
  • 81
  • 122
Michael
  • 31
  • 1
2

launch_stack.bat will open 2 windows to run your alices.bat and bobs.bat

start alices.bat
start bobs.bat
Hà Mã Tím
  • 143
  • 2
  • 3
1

If we simply use start command or start cmd.exe it opens cmd.

If you want to open the same command prompt window;

start "Command Prompt"
Irfan wani
  • 4,084
  • 2
  • 19
  • 34
0

I also tried executing batch file that run daemon process/server at the end of CCNET task; The only way to make CruiseControl spawn an independent asynchronous process WITHOUT waiting for the end of process is:

  1. create a batch file to run the daemon process (server application)
  2. use task scheduler to run the batch file as CCNET task (using schtasks.exe)

    schtasks.exe /create /F /SC once /ST 08:50 /TN TaskName /TR "c:/path/to/batchFileName.bat"
    
    • 08:50 is the HH:MM time format

you might need to kill the process at the start of ccnet

PS: the selected answer using "start cmd.exe" does not work; a new command prompt is indeed spawned, but CCNET will wait for the spawned cmd to finish.

kite
  • 1,478
  • 1
  • 15
  • 27
0

You can write in command line this command

cmd

Previous command will open in current command line with new session

OR

start

Eng_Farghly
  • 1,987
  • 1
  • 23
  • 34