[comp.unix.shell] execute stdin ?

wittig@gmdzi.gmd.de (Georg Wittig) (09/13/90)

Is it possible (in sh or in csh) to execute a program that is read from
stdin? For example, if the program ``myprog'' is in compressed format, it
isn't nice to type

	uncompress myprog.Z ; myprog params_of_myprog ; compress myprog

Rather, it would be nice to be able to write something like

	zcat myprog.Z | execute_stdin params_of_myprog
or	`zcat myprog.Z`	params_of_myprog
or	???

Any ideas? Thanks in advance
-- 
Georg Wittig  GMD-Z1.IT	| wittig@gmdzi.gmd.de	| "Freedom's just another word
P.O. Box 1240		| wittig@zi.gmd.dbp.de	|  for nothing left to lose"
D-5205 St. Augustin 1	|			| (Kris Kristofferson)
West Germany		| (+49) 2241 14-2294	|

guy@auspex.auspex.com (Guy Harris) (09/16/90)

>Is it possible (in sh or in csh) to execute a program that is read from
>stdin?

It's possible, although the ways you can do it depend on whether the
"program" is an executable image or a script.

If it's a script, you can try piping it to the interpreter (shell or
whatever).

If it's an executable image, in most UNIXes you must either put it into a
file, or construct some program that reads its standard input and sets
up its address space to contain the executable image it's reading and
then jumps to it.

jms@romana.Tymnet.COM (Joe Smith) (09/27/90)

In article <3335@gmdzi.gmd.de> wittig@gmdzi.gmd.de (Georg Wittig) writes:
>Is it possible (in sh or in csh) to execute a program that is read from stdin?

Yes, use the "-s" option to sh.  For example:

	(echo 'ls -l $1'; echo 'wc $1') | sh -s /etc/motd

As simple as that.
-- 
Joe Smith (408)922-6220 | SMTP: jms@tardis.tymnet.com or jms@gemini.tymnet.com
BT Tymnet Tech Services | UUCP: ...!{ames,pyramid}!oliveb!tymix!tardis!jms
PO Box 49019, MS-C41    | BIX: smithjoe | 12 PDP-10s still running! "POPJ P,"
San Jose, CA 95161-9019 | humorous dislaimer: "My Amiga 3000 speaks for me."