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

后端 未结 3 882
慢半拍i
慢半拍i 2020-12-20 09:02

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<<         


        
相关标签:
3条回答
  • 2020-12-20 09:13

    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
    
    0 讨论(0)
  • 2020-12-20 09:14

    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.

    0 讨论(0)
  • 2020-12-20 09:26

    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.

    0 讨论(0)
提交回复
热议问题