Menu

Extracting data from 'system' 'set command.

David Wall
2021-10-26
2021-10-26
  • David Wall

    David Wall - 2021-10-26

    I'm trying within a cobol program to run a system 'set' command and then extract data from the result.
    eg: call 'SYSTEM' using syscom - where the contents of syscom are as follows for example:

    SET | FINDSTR /c:FRED ????????
    Run the SET command and pipe the output to FINDSTR looking for the word FRED.

    Run this at command prompt and the displayed result might be : FRED=GOHOME or FRED=STAYHERE or of course nothing if the term FRED didn't exist as an EV.

    I'm trying to capture the FRED=GOHOME or FRED=STAYHERE or nil as a field in my program.

    I 'could' say SET | FINDSTR /c:FRED > filename but that would then involve opening that file and reading the contents each time - a bit wasteful.

    Is there any other smart way of capturing the output of FINDSTR directly in my code. ??

     
    • Simon Sobisch

      Simon Sobisch - 2021-10-26

      Hm, concerning the set statement I'd get rid of findstr completely set FRED will only return this one.
      Concerning the original question: yes: that's possible with NOT using the SYSTEM command as the only way to work with the result is redirection and file opening.

      For MF and GC4+ you can use pipes as "names" for "files" - OPENing them will then lead your READ to get the result.

      For all other cases: call popen manually or with a nice wrapper like https://sourceforge.net/p/gnucobol/contrib/HEAD/tree/trunk/tools/cobweb/cobweb-pipes/cobweb-pipes.cob

       
  • David Wall

    David Wall - 2021-10-26

    Brill !! - thanks Simon - much appreciated.

     

Anonymous
Anonymous

Add attachments
Cancel