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. ??
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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. ??
Hm, concerning the set statement I'd get rid of findstr completely
set FREDwill only return this one.Concerning the original question: yes: that's possible with NOT using the
SYSTEMcommand 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 yourREADto get the result.For all other cases: call
popenmanually or with a nice wrapper like https://sourceforge.net/p/gnucobol/contrib/HEAD/tree/trunk/tools/cobweb/cobweb-pipes/cobweb-pipes.cobBrill !! - thanks Simon - much appreciated.