Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!edcastle!lfcs!kgg From: kgg@lfcs.ed.ac.uk (Kees Goossens) Newsgroups: comp.windows.x Subject: Re: io redirect of xterm -e cmd Message-ID: <3227@castle.ed.ac.uk> Date: 10 Apr 90 09:50:05 GMT References: <3222@castle.ed.ac.uk> <9005@chaph.usc.edu> Reply-To: kgg@lfcs.ed.ac.uk (Kees Goossens) Organization: Laboratory for the Foundations of Computer Science, Edinburgh U Lines: 59 In article <9005@chaph.usc.edu> jeenglis@alcor.usc.edu (Joe English) writes: >kgg@lfcs.ed.ac.uk (Kees Goossens) writes: >>I would like to redirect some of the output of a program I usually run as >>xterm -e program into a separate X window. >>Why doesn't the following work? >> >>{ >> FILE *f; >> f = open ( "/tmp/zap", "w" ); >> system "/usr/local/bin/X11R4/xterm -e cat /tmp/zap"; >> >> ... here I use fprintf(f,...); for writing to that X window >> and fprintf(stdout,...); for writing to the X window in >> which the program was started ... >> >> fclose(f); >>} > >The problem is, cat only reads to the end of the file >and then exits. > >If you use 'tail -f' instead of 'cat' in the call to >system() it will work, but you have to get the pid >of the tail or xterm process and kill it or else it >will never exit. The following works: { FILE *file = NULL; int i = 0; if ( ( file = fopen ( "tmp", "w" ) ) == NULL ) { printf("Could not open file\n"); exit(-1); } system ("xterm -geometry 80x24+0+0 -e tail -24lf tmp &"); for (i=0; i<100; i++) fprintf ( file, "Hello there %d\n", i ); fclose(file); ... and need to kill xterm here ... } > >A better solution would be to use 'f=popen("xterm -e cat")' >instead of a temporary file. > This does not work, as the stdin is inside the window, rather than f, so it'll just sit there until you type ^D inside the window. Is there a way of curing this? (It'd be nicer than the solution above.) >--Joe English Kees ---- Kees Goossens Keep in Touch with the Dutch: LFCS, Dept. of Computer Science JANET: kgg@lfcs.ed.ac.uk University of Edinburgh UUCP: ..!ukc!lfcs!kgg Edinburgh EH9 3JZ, UK. ARPA: kgg%lfcs.ed.ac.uk@nsfnet-relay.ac.uk