I have an already-started console application, under Windows XP. I want to attach it to a different console emulator such as Console2 or ConEmu. This is possible with ConEmu, and it works if I run ConEmu then use its "Attach to" menu entry and select my console application in the list.

I am now trying to automate this. I want to be able to focus the console application window, press a key, and have it attached to a new instance of ConEmu. I tried to write an AutoHotKey macro to attach the currently focused console application when I press Win+A, but I can't figure out how to use ConEmuC. Here's my attempt:

#IfWinActive, ahk_class ConsoleWindowClass
  WinGet, app_pid, PID
  Run c:\opt\ConEmu-120704\ConEmu.exe /detached, , , conemu_pid
  Run c:\opt\ConEmu-120704\ConEmu\ConEmuC.exe /ATTACH /PID=%app_pid%

All I get the following error popup:

Attach to GUI was requested, but there is no console processes!

c:\opt\ConEmu-120704\ConEmu\ConEmuC.exe /ATTACH /PID=7104

Yet if I use the “Attach to” menu entry in the ConEmu instance, the console application gets attached. I need to tick the “alternative mode” checkbox introduced in version 120704, if that's relevant.

How do I use ConEmuC (or any other method) to attach an existing console application to a new ConEmu instance? Even better, how do I attach an existing instance (if I want a new instance, I can just create it beforehand)? And how do I specify alternative mode?

1 Answer 1


Try the following

#IfWinActive, ahk_class ConsoleWindowClass
  WinGet, app_pid, PID
  Run c:\opt\ConEmu-120704\ConEmu\ConEmuC.exe /ATTACH /CONPID=%app_pid%

Alternative mode: /ATTACH /CONPID=<pid>.

Starting ConEmu.exe /detached is unnecessary. GUI will be started automatically, if not found.

UPD. Build 120705. If you want to unconditionally start new ConEmu window, you may add /GHWND=NEW to ConEmuC arguments.

UPD 2. On the other hand, may be you do not need to do Attach at all? There is Default terminal feature which allows you to run ConEmu automatically "instead" of standard windows terminal when you run any console application.

  • Ah, /CONPID, ok. Is there a way to specify that I want a new ConEmu window and not a new tab in an existing window? Jul 5, 2012 at 18:56
  • If you want new ConEmu window, run ConEmu.exe /detached and wait a little, while GUI window will be created. In the current version there is no special switch in ConEmuC for this case.
    – Maximus
    Jul 5, 2012 at 19:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .