I can't test this idea since I haven't run windows in a while, but perhaps a poor-man's version could work like so:
1. Start two consoles and determine the pids of the cmd.exe's running in the two consoles by running the following command in each terminal (I've never used this command before, so I don't know if it'll work) :
wmic process get parentprocessid,name|find "WMIC"
2. Run your program in one of the consoles, passing in the two pids as command line arguments with the pid belonging to the current console first.
3. To write to the other console, you detach from the current one and attach to the other one, write something, then switch back.
The cmd.exe processes will keep the consoles open when you free them (if no process is using a console, it's destroyed). They also provide pids that you can use to (re)attach to the consoles.
Maybe someone could try this.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <windows.h>
DWORD pid_main, pid_other; // global for convenience
void print_other(const char *fmt, ...) {
FreeConsole();
AttachConsole(pid_other);
va_list va;
va_start(va, fmt);
vprintf(fmt, va);
va_end(va);
FreeConsole();
AttachConsole(pid_main);
}
int main(int argc, char **argv) {
if (argc != 3) {
fprintf(stderr, "Usage: dualconsole current_pid other_pid\n");
exit(EXIT_FAILURE);
}
pid_main = atoi(argv[1]);
pid_other = atoi(argv[2]);
printf("starting main\n");
print_other("starting other\n");
for (int i = 0; i < 10; i += 2) {
printf("%d\n", i);
print_other("%d\n", i + 1);
}
printf("done\n");
return 0;
}