Re: How to execute shell command and store result to variable?
Posted in 1997
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Because Informix uses the exit code on the run returning it will not return the number of files from wc. To accomplish this you need to create a script file like this: MCOUNT=`ls|wc -l` exit $MCOUNT in your 4gl program it should look something like this: LET run_txt="<script filename>" RUN run_txt RETURNING tot_file LET tot_file=tot_file/256 IF tot_file < 3 THEN ERROR "Incomplete files! Process aborted!" SLEEP 3 EXIT PROGRAM END IF this should accomplish what you need. Hope this helps. --- ,-, |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| ======= ___|| | | ----- //_ || | CANNON EXPRESS | ---- ,-----'| ~ | | | -- |o-----|__ |--`======_______________________________======___| ~~~~~~~~ `-(*)--===~~~~~~(*)(*)| (*)(*)| ------- ------------------------------------------------------------------------- Joseph Cullipher |E-mail: joseph@cannonexpress.com PO Box 364 |opinions express are those of my own and Springdale, AR 72764 USA |don't necessarily reflect those of my company ------------------------------------------------------------------------- On Fri, 21 Mar 1997, EHLIM wrote: > > Hi Informix programmers, > > > Can I run a Unix shell command like " ls .... | wc -l " and store the result > into a variable for my program varification purpose. So, if my program > checked that number of files in the directory were less than 3, prompt error > messages, otherwise continue. > > I tried this but it doesn't work:- > > LET run_txt="ls ..... | wc -l" > RUN run_txt RETURNING tot_file > IF tot_file < 3 THEN > ERROR "Incomplete files! Process aborted!" > SLEEP 3 > EXIT PROGRAM > END IF > > > The variable tot_file shows value 1 means the shell command has been > sucessfully executed, but not the total number of files in the directory. > > Please reply via email to ehlim@resorts.po.my > > Many thanks in advance! >