csh question

Hans Mulder hansm at cs.kun.nl
Wed Mar 27 02:51:14 AEST 1991


In article <1991Mar21.005808.12432 at mintaka.lcs.mit.edu> dbert at pogo.gnu.ai.mit.edu (Douglas Siebert) writes:
>OK, here's another good one:  in csh you can type ctrl-Z to stop a process
>and then use fg to return to it, right?  Now, is there any way to (before
>you return to the process using fg) pipe some output to that process in
>some way so that it will be like the process itself received that as input?
>Either through redirecting that process' standard input from the outside
>or piping some output some way directly to that process?

Well, if you want to feed less than 255 bytes into your process, you might
try using ioctl(0,TIOCSTI,ch) if your system supports it.  This plugs bytes
into the terminal driver's input queue and from where they will be read by
the next process that tries to read anything from your terminal.

So you could start by ioctling the characters 'f', 'g' and '\n', followed
by some input for your stopped process.  When your ioctling program is done,
csh reads the fg command and resumes your stopped process.

Or you could type a command like "my_ioctling_prog; fg".

>Thanks for any help (and if there *is* some way I can do something similar in
>a shell other than csh, I'd be interest in that as well, especially in sh or
>ksh since those are relatively universal)

The sh on most Unix systems is the one written by Steve Bourne.  That
one does not handle ctrl-Z in any way.  If the sh in your system does
handle ctrl-Z, then it is the rewrite by David Korn.  That one handles
ctrl-Z in pretty much the same way as csh.  Ksh is the name of Korn's
shell on systems where sh is Bourne's.


But maybe you really wanted something along these lines:

#!/usr/local/bin/perl

open(OUT,"|xxxxx");
select(OUT);
$|=1;

while(<>) {
    if (/\|$/) {
        open(PIPE,$cmd=$_);
        while(<PIPE>) {
            print OUT;
        }
        close(PIPE);
	print STDERR "Problem $? while running $cmd" if $?;
    } else {
	print OUT;
    }
}

This will copy your input lines into "xxxxx", except those that end
in a '|'.  Such lines are interpreted as commands, and their output
is piped into "xxxxx".


Have a nice day,

Hans Mulder	hansm at cs.kun.nl



More information about the Comp.unix.shell mailing list