redirect child output in another xterm window

redirect child output in another xterm window

Post by qazm » Sun, 07 Oct 2001 14:21:23



#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/stat.h>

#define REDIRECT_FILE  "/home/ic/map.display"

int main()
{

   printf("i am in parent") ;
   int childPid ;
   mkfifo( REDIRECT_FILE,  S_IRUSR | S_IWUSR );
   if( childPid= fork()==0)
   {
     close(0); close(1); close(2);
     int file_desc = open( REDIRECT_FILE , O_WRONLY );
     dup2( file_desc , 0);
     dup2( file_desc , 1);
     dup2( file_desc , 2);

      printf("child output");

     //char *const args[5] = { "xterm", "-e", "/bin/cat",
REDIRECT_FILE, NULL } ;

     char *const args[6] = { "xterm", "-e", "tail", "-f",
REDIRECT_FILE , NULL } ;

     execvp("xterm",args);

     printf("child output");

     sleep(1000) ;
     close(file_desc);

   }

   sleep(1000);
   return 0;

Quote:}

Here, the child process output should be displayed in another xterm
window.
The above code only opens a window, but didn't output the things.
What am I doing wrong ?
 
 
 

redirect child output in another xterm window

Post by Andrew Gabri » Sun, 07 Oct 2001 19:21:33




Quote:>#include <stdio.h>
>#include <unistd.h>
>#include <fcntl.h>
>#include <signal.h>
>#include <sys/stat.h>

>#define REDIRECT_FILE  "/home/ic/map.display"

>int main()
>{

>   printf("i am in parent") ;
>   int childPid ;
>   mkfifo( REDIRECT_FILE,  S_IRUSR | S_IWUSR );
>   if( childPid= fork()==0)

Warning: operator precedence is wrong here (although not the
cause of your immediate problem)

Quote:>   {
>     close(0); close(1); close(2);
>     int file_desc = open( REDIRECT_FILE , O_WRONLY );

You block here until something else also opens the fifo for reading,
which thus never happens.

Quote:>     dup2( file_desc , 0);
>     dup2( file_desc , 1);
>     dup2( file_desc , 2);

>      printf("child output");

>     //char *const args[5] = { "xterm", "-e", "/bin/cat",
>REDIRECT_FILE, NULL } ;

>     char *const args[6] = { "xterm", "-e", "tail", "-f",
>REDIRECT_FILE , NULL } ;

>     execvp("xterm",args);

Warning: You shouldn't ever get here (only if the execvp fails)

- Show quoted text -

Quote:>     printf("child output");

>     sleep(1000) ;
>     close(file_desc);

>   }

>   sleep(1000);
>   return 0;

>}

>Here, the child process output should be displayed in another xterm
>window.
>The above code only opens a window, but didn't output the things.
>What am I doing wrong ?

You should probably be using xterm with a pseudo tty.
See an article I wrote some time back:
http://groups.google.com/groups?oi=djq&selm=an_618136725

--
Andrew Gabriel
Consultant Software Engineer

 
 
 

1. How Cron job open Xterm window and display outputs to this xterm?

Hi,

Please help.  I tried to set up a cron job to:
1.  Open xterm window
2.  Run my script from this xterm
3.  display any errors or output from the script to this xterm.

The reason I need this because the script that I launch from cron job
required user input and it could NOT feed in with regular <<EOF option.

Thanks

--
Posted via http://dbforums.com

2. Caldera Linux: LILO win95 tag does not start win95

3. redirect output from child process into parent's stdout

4. Delivery of signals Question

5. Problems redirecting a child's output

6. X with S64 graphics card

7. X-Windows not redirecting console output to console window

8. Questions about Old PC resurection w/Linux.

9. Q about Redirecting childs output to parent

10. Redirecting output to file and xterm in bash

11. Redirecting Console output to Xterm??

12. redirecting i/o from child to other terminal window

13. Child of xterm window doesn't see signal when parent receives SIGINT