I would like to invoke a cobol program thru shell script by assigning command line prompt values in the "EOD" as below.
#!/bin/bash
run pub/coblprog<<:EOD:
1
2
3
:EOD:
Consider if COBOL program "coblprog" has 4 command line prompts and expects 4 input command line arguments at runtime. I have specified 3 prompt values in the EOD. Since COBOL has four prompts but at EOD does passing 3 values , COBOL program is going into infinity loop to expecting the fourth prompt value.
My requirement is, I would like to set an shell's control break statement (like below) after all prompt values before second :EOD:. By seeing that shell's control statement the the shell script should terminate abnormally.
#!/bin/bash
run pub/coblprog<<:EOD:
1
2
3
exit 1
:EOD:
I have have exit statement in the script and run, but no luck..! Please suggest me good solution.
I am executing the script in LINUX, COBOL program is Micro Focus COBOL.
The data from the line after <<:EOD: until the line just before the one beginning :EOD: is input to the COBOL program, and not shell control statements, therefore the exit 1 will be data, which is probably not what you want.
If you want the shell script to exit after running coblprog, then place it after the line beginning :EOD:.
#!/bin/bash
run pub/coblprog<<:EOD:
1
2
3
4
:EOD:
exit 1
I am not at all familiar with your COBOL interpreter, but if it is at all properly programmed, it should also exit when no more input is available. If that is so, then feeding it three lines of input instead of four should be sufficient. However, it appears that you already tried that.
As a somewhat crude workaround, you could connect it to a FIFO and kill it a while after feeding it the last line of input.
#!/bin/sh
fifo=/tmp/cobolfifo.$$ # insecure, should have more randomness
mkfifo $fifo
cat >>$fifo <<HERE &
1
2
3
HERE
run pub/coblprog <$fifo &
cobol=$!
sleep 5
kill $cobol
rm $fifo
Whether five seconds is sufficient is anybody's guess. If there is any way you could change the COBOL program so that this isn't necessary, that's probably the sanest solution.
OK, not answering questions asked of you, so... shot-in-the-dark time.
Your program is not looping.
It looks like this, doesn't it?
PROCEDURE DIVISION.
ACCEPT VAR1.
ACCEPT VAR2.
ACCEPT VAR3.
ACCEPT VAR4.
I've even coded the pointless dots.
You are stacking up three "user inputs" in your script.
The first ACCEPT takes the first, the second the second, and the third the third.
The fourth ACCEPT finds no data waiting for it, so it waits... for you. To type. It is not looping, it is just waiting for input. You Ctrl-C, and dismiss it as a loop.
If you have four ACCEPTs, you need four entries of data. Either supply four in the script, or supply the fourth "manually", or change the program so that it only ACCEPTs three.
来源:https://stackoverflow.com/questions/21903596/setting-shells-control-break-statement-in-the-standard-input-stream-eod-to-ex