Re: How to execute shell command and store result to variable?
Posted in 1997
Is your real problem to count the number of files in a directory, or is it generaly to return values from shellscripts? In the last case some suggestions have been given. If you realy want to count files I would go for a C-language interface that did the count and returned that directly. A quiq scan of the C-libraries at http://www.iiug.org didn't show any library that contained code to read a directory. It should however be reasonably easy to write one. I don't write much C, but would love to see such code (hint, hint...). Also someone suggested that you write the output of a Unix command to a file and then use the load command to read it into a table to get at it from 4GL. Although this does give you way to do such a thing with 4GL only, we have found the use of a C-library to read files directly faster, easier and much more flexible. There are several such libraries at the IIUG site. (They could all be significantly better, but they do work.) ehlim@resorts.po.my (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! : Nils.Myklebust@idg.no NM Data AS, P.O.Box 9090 Gronland, N-0133 Oslo, Norway My opinions are those of my company The Informix FAQ is at http://www.iiug.org