Redirect ouput to another instance terminal window.

This is a discussion on Redirect ouput to another instance terminal window. within the C++ Programming forums, part of the General Programming Boards category; Hi friends, I have a simple question to ask. How can I open a new terminal window from a C++ ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    Redirect ouput to another instance terminal window.

    Hi friends,

    I have a simple question to ask. How can I open a new terminal window from a C++ program so that i can redirect the output that i want to monitor during the execution of a program, I don't want to use the same terminal window from which I am running the code. This doesn't sound so difficult but I couldn't find a solution on google. I am running the code on a Linux machine and using GCC.

    Thanks,
    John.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    #include <unistd.h>
    
    FILE *LaunchLogWindow()
    {
        char *name = tempnam(NULL, NULL);
        char cmd[256];
    
        mkfifo(name, 0777);
        if(fork() == 0)
        {
    	sprintf(cmd, "xterm -e cat %s", name);
    	system(cmd);
    	exit(0);
        }
        return fopen(name, "w");
    }
    
    int main()
    {
        FILE *log = LaunchLogWindow();
        for(;;)
        {
    	fprintf(log, "Hello world!\n");
        }
    }
    A few bits are missing. Nothing cleans up the FIFO. I don't check for errors. It uses a C FILE object instead of a C++ ofstream. But you get the point.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 09:23 AM
  2. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 06:57 AM
  5. Invoking MSWord
    By Donn in forum C Programming
    Replies: 21
    Last Post: 09-08-2001, 05:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21