Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we open multiple terminals for showing the output in C on Windows?

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.

like image 968
user3682339 Avatar asked Oct 19 '25 13:10

user3682339


1 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

  1. Create a new processes and execute in it the first one
  2. 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.

like image 133
Alberto Lerda Avatar answered Oct 21 '25 04:10

Alberto Lerda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!