Setting shell's control break statement in the standard input stream “EOD” to exit the COBOL program

人盡茶涼 提交于 2019-11-29 13:02:47

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!