I want to open multiple terminals when I run my code on Dev C++. I want to show different outputs on different terminals. On one terminal I want to show the activity log of whatever is happening in the code, and the other terminal should show the result I have generated.
-
2look here http://stackoverflow.com/questions/6803327/is-it-possible-to-output-on-multiple-terminal-windows-within-a-single-c-program?rq=1 – Jayesh Bhoi May 28 '14 at 06:12
-
1This is on linux, I am working on windows – user3682339 May 28 '14 at 06:39
-
For C++ there seems to be a nice library here: http://code.google.com/p/multi-console/ Studying the sources might enlight you to how this can be done in plain C using win32-api calls. – alk May 28 '14 at 08:41
4 Answers
When you program is executed it is a process.
If you want two consoles, you need two process, that is two programs. Moreover, they have to be able to comunicate
The first is relatively simple, it only print to screen whatever he receives as input.
On the other hand, the second has to
- Create a new processes and execute in it the first one
- Open a pipe and send to the first process what you want to print to screen.
This article is quite detailed on how to do this https://learn.microsoft.com/en-us/windows/win32/procthread/creating-a-child-process-with-redirected-input-and-output (it says it is for C++ but it works also in C). Pay attention, to the "creation flags" you have to pass CREATE_NEW_CONSOLE
.

- 401
- 2
- 7
You can create a wrapper program that calls your original program when needed to open multiple instances of the original program. This is fairly simple on windows. Just run the wrapper and have that call your program instances to have multiple windows open. You can even give arguments to your wrapper program for more flexibility. Just create #define
flags and have multiple versions of your program compiled, and have the wrapper call them. For example if #define log
is defined, then have the program only show logs, if #define output
is defined, have it show outputs. Then after compiling the program with different flags, inside your wrapper, call them like this: system("start logger.exe"); system("start output.exe")
See this question for detailed information on how to start another process.
If you want those running programs to interact with each other it gets a lot more complicated, an easy work-around would be to have them read/write from a file using fopen
to send information in-between eachother, but depending on your needs it can get really complicated.
Since a program itself, like the other question mentioned, is just an instance and a single process all of those options are a workaround, the closest you can get that is not a work-around is threading, it's not quite what you want but you can check it out.

- 711
- 3
- 25
As other answers mention, you can't have one program directly output to multiple terminals. The only option is to have some kind of IPC (inter process communication) solution.
There are multiple options here:
- You could create a program which does all your actual work (generating results, logging, etc.) and then create another program which talks to the original program to retrieve whatever information it wants to print to the terminal. In order for your two programs to communicate, you can use sockets or pipes.
- Have one program do the actual work, and log all the various types of information to their own respective log files somewhere on the local file system. Then you can just run following PowerShell script
Get-Content -Wait -Path $desiredFilePath
. This command will dump the entire contents of the given file, and then periodically check if anything new has been added to the file, and if so dump that as well.

- 111
- 7
Log activity to a separate window with a single edit control
- Create new window with a single edit control, the activity window
- New window waits for custom private message and appends contents to Edit control
- Update activity logger to send a private message using SendMessage to activity window every time activity is logged.

- 2,483
- 14
- 24