Search code examples
windowsbatch-filecmdexestartup

How I can start console application from bat / cmd file, so the console output will be inside bat?


I tried this:

start patcher.exe pause

Then new console window of my app appears.

and this:

cmd.exe patcher.exe pause

Appears cmd without execution of my prog.

and this:

cmd.exe patcher pause

Then appears cmd, I must type "exit" and then my pro starts, but in new console again.

I need my console to not appear, but write all messages in that started bat.


Solution

  • The reason that this didn't work

    cmd.exe patcher.exe
    

    is that isn't how you pass a command to cmd.exe. Try

    cmd.exe /C patcher.exe
    

    or

    cmd.exe /K patcher.exe
    

    However, that's not likely to remove the duplicate console window. What's probably going on is that patcher.exe is marked as Windows subsystem, so it isn't associated with the console that launches it. Then it launches child processes which are console applications, and since there's no associated console, a new one is created.

    You could try using EDITBIN patcher.exe /SUBSYSTEM:CONSOLE to make patcher.exe a console-mode program as well. Then the console will propagate from parent to patcher (child) to grandchild. However, since the program wasn't written or tested to run this way, you could find some unintended consequences.