[comp.windows.x] io redirect of xterm -e cmd

kgg@lfcs.ed.ac.uk (Kees Goossens) (04/10/90)

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);
}
	
I gather xterm's stdin, and stdout are not the same as cat's.
I don't really want lots of X wizardry in my program...

Thanks,
	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

jeenglis@alcor.usc.edu (Joe English) (04/10/90)

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.

A better solution would be to use 'f=popen("xterm -e cat")' 
instead of a temporary file.


--Joe English

  jeenglis@nunki.usc.edu

kgg@lfcs.ed.ac.uk (Kees Goossens) (04/10/90)

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

janssen@parc.Xerox.COM (Bill Janssen) (04/11/90)

> I would like to redirect some of the output of a program I usually run as
> xterm -e program into a separate X window.

I've been using the Andrew pipescript tool for this, and it's pretty handy.
It just reads its standard input and displays it in a scrollable read-only
text editor window (which allows for things like searches).  It also mentions
when an end-of-file has been reached on the standard input.

Useful for things like 'ps auxww | pipescript'.
--
 Bill Janssen        janssen.pa@xerox.com      (415) 494-4763
 Xerox Palo Alto Research Center
 3333 Coyote Hill Road, Palo Alto, California   94304