Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

No terminal output using call "system" in JVM COBOL

No terminal output using call "system" in JVM COBOL

Problem

When using call "system" to start a a new process from a JVM COBOL program, ACCEPT and DISPLAY statements in the new process do not work.

Resolution

The JVM runtime uses the underlying support in Java’s Process class which is written to be portable etc.  This has the side effect than on Unix/Linux the support it has no notion of terminal I/O.

So, this means that you can’t use CALL “system” in JVM where the new process is doing terminal i/o.  However there is a work-around.  You can use xterm –e to start a new X-term window and run a script.  For example, here is a demo where test1.cbl calls a script, runs2.sh.  The script set-ups the environment needed for cobjrun.  This is required due to a Unix/Linux security feature which prevents spawned processes from inheriting the LD_LIBRARY_PATH.

For the demo both test1.cbl and test2.cbl were compiled with cob –j.  To run use cobjrun test1.


test1.cbl:

        01  ws-runit-id pic x(8) comp-5.
        01  ws-stack    pic x(4) comp-5.
        01  ws-flags    pic x(4) comp-5 value 1.
        01  ws-status   pic x(4) comp-5.

        procedure division.

        display "in test 1"

        call "system" using z"xterm -e /runs2.sh"

        display "back in test 1"
        goback.


runs2.sh:

export LD_LIBRARY_PATH=$COBDIR/lib:$LD_LIBRARY_PATH
cobjrun test2


test2.cbl:

        01 ws-key pic x.

        procedure division.

        display "in test 2 - press a key"
        accept ws-key
        display "you pressed " ws-key
        goback.

NOTE – The DISPLAY environment variable needs to be set to an X-Windows server.  If running a terminal emulator from Windows you will require an X-Windows server running on the PC to allow the new window to be created on the PC’s screen.

When you run the demo, test1 uses the main terminal window.  When the runs2.sh script is run a new window is created and all accept and display i-o in test2.cbl goes to the new window.  When test2 terminates, the window is destroyed and test1 continues in the original terminal window.

The xterm command takes lots of parameters which allow you to configure the look and feel of the new window.

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2015-11-30 23:51
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.