Xref: utzoo comp.unix.wizards:5877 comp.unix.questions:4885 comp.lang.c:5859 Path: utzoo!mnetor!uunet!munnari!natmlab!basser!metro!ipso!runx!nrowe From: nrowe@runx.ips.oz (Nigel Rowe) Newsgroups: comp.unix.wizards,comp.unix.questions,comp.lang.c Subject: Re: Help! How 2 get info from C to Unix script Message-ID: <1273@runx.ips.oz> Date: 15 Dec 87 08:37:09 GMT References: <1569@ssc-vax.UUCP> <12702@think.UUCP> Reply-To: nrowe@runx.OZ (Nigel Rowe) Organization: RUNX Un*x Timeshare. Sydney, Australia. Lines: 41 In article <12702@think.UUCP> barmar@sauron.UUCP (Barry Margolin) writes: >In article <1569@ssc-vax.UUCP> bact@ssc-vax.UUCP (Archie A. Auxter) writes: >> Is there a way >>that I can call my program within a Unix script and set a variable in the Unix script >The way to do this is to have your program print the filenames to >stdout. You can then pipe the output into the command line using >`command line`, e.g. > >FILE_PICKED=`program args` > >Note that since this redirects stdout, when your program interacts >with the user it will have to open /etc/tty directly, not use stdout. > There are other tricks like this, for example I use a menu driver that outputs (to stdout) lines like name='value' othername='something else' ... etc and is called from (bourne) shell scripts like this eval `menu screen_file` || exit which will then set numerous shell vars. The " || exit" copes with the menu "cancel" key by causing menu to exit(1) which causes the script to exit as well. Rather than directly opening /dev/tty I send the user interaction to stderr, this works just as well (as stderr is connected to the tty by default), but allows me to do tests without having to look at the menu screen. eg. eval `menu screen_file 2> /dev/null` || exit or use a log file instead of /dev/null. -- Nigel Rowe ACSnet: nrowe@runx.ips CSNET: nrowe@runx.ips.oz ARPA: nrowe%runx.ips.oz@seismo.css.gov JANET: runx.ips.oz!nrowe@ukc UUCP: ...!{seismo,mcvax,ukc,ubc-vision}!munnari!runx.ips.oz!nrowe