HP 3000 Manuals

Calling Operating System Functions [ Micro Focus COBOL for UNIX COBOL User Guide ] MPE/iX 5.0 Documentation


Micro Focus COBOL for UNIX COBOL User Guide

Calling Operating System Functions 

The COBOL run-time system sets the terminal to a mode suitable for COBOL.
Calls to "system" fail because they do not affect the mode, as terminal
settings are not modified before or after the call.

You should replace your calls to "system" with calls to "SYSTEM":  this
is a subroutine provided with this COBOL system so that your operating
system can perform the same operations as system( ), but return the
terminal to shell mode before executing the command.  The format of this
command is:

     call "SYSTEM" using cmd-line 

where the parameter is:

cmd-line              A null-terminated command line

Upon completion of the call "SYSTEM" statement, the terminal is reset to
the mode suitable for COBOL. For example:

      01  cmd-line   pic x(3)  value "sh" & x"00".
      01  cmd-line2  pic x(30) value "cp f1 f2 >errfile 2>&1" & x"00".

      procedure division.
          display "Test" at 1101
          call "SYSTEM" using cmd-line
          display "Back in program" at 1201
          call "SYSTEM" using cmd-line2
          display "Back in program" at 1301
          stop run.

As COBOL is unaware of any output from either call "system" or call
"SYSTEM", you must ensure that your screen is either not updated by a
call or is redisplayed after execution of the call.

In the example above the first command-line executed is the sh command,
which will update the screen with the system prompt and any commands that
may be entered.  The second command-line copies file f1 to file f2 and
redirects both the standard output and the standard error to the file
cp.log which your program can open in order to read any output generated
by running the command.  The order in which you make the redirections is
significant.



MPE/iX 5.0 Documentation