Reputation: 113385
How to start a child process in GnuCOBOL?
In Node.js, we can use either spawn
or exec
to start child processes:
var proc = require("child_process").spawn("ls", ["-l"]);
proc.stdout.on("data", function (chunk) {
console.log(chunk);
});
// or
var proc = require("child_process").exec("ls -l"], function (err, stdout, stderr) {
...
});
Both of the examples above run ls -l
(list the files and directories). How can the same thing be achieved in COBOL?
Upvotes: 3
Views: 329
Reputation: 7287
Use a common COBOL extension which is supported since years in GnuCOBOL (formerly OpenCOBOL), too:
CALL 'SYSTEM' USING whatever END-CALL
This works with 'cobcrun', too and can be useful if you need a COBOL process with a separate environment (EXTERNAL
items, ACCEPT x FROM y
/ SET ENVIRONMENT y TO x
) or runtime configuration (for example via cobcrun -c different.cfg OTHERMAIN
).
Your original sample may look like (without the option to use pipes which would be a different question):
CALL 'SYSTEM' USING 'ls -l >dirlist'
ON EXCEPTION
CALL 'SYSTEM' USING 'dir >dirlist'
END-CALL
END-CALL
Afterwards you can read the dirlist as a normal line sequential file.
Simon
BTW: Given your sample you may look for CALL 'C$LISTDIR'
.
Upvotes: 5