Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!mcsun!hp4nl!sci.kun.nl!cs.kun.nl!hansm From: hansm@cs.kun.nl (Hans Mulder) Newsgroups: comp.unix.shell Subject: Re: csh question Message-ID: <2895@wn1.sci.kun.nl> Date: 26 Mar 91 16:51:14 GMT References: <1991Mar21.005808.12432@mintaka.lcs.mit.edu> Sender: root@sci.kun.nl Organization: University of Nijmegen, The Netherlands Lines: 59 In article <1991Mar21.005808.12432@mintaka.lcs.mit.edu> dbert@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() { 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@cs.kun.nl