Issuing Operating System Commands


How to:

You can issue an operating system command to set up an environment in which a request must run. For example, a program may change directories, rename files, unzip files, copy files, or perform other operations before executing a request. After the environment is customized, the program can begin the report and graph requests.

Syntax: How to Execute an Operating System Command

op_system command



Specifies the operating system.

-DOS or DOS specifies the DOS operating system.

-MVS or MVS specifies the MVS operating system.

-TSO or TSO specifies the TSO operating system.

-UNIX or UNIX specifies the UNIX operating system.

-WINNT or WINNT specifies the Windows operating system.

-VMS or VMS specifies the OpenVMS operating system.

-AS/400 or AS/400 specifies the IBM i operating system, which is also known as AS400 or OS400.

-SYSTEM or ! specifies any operating system.


Is an operating system command.


  • The difference between prefixing the operating system with or without a “-” (dash) is that dash prefixed operating system commands can run within a stream of dialogue manager commands without the need for a -RUN to force execution. Additionally, a dash prefixed operating system command is ignored (bypassed) if the command is not actually run on that operating system. For example, if an application runs on several different operating systems and you want to display the current directory, which requires a different command for each operating system, you can simply use the following code:
    -UNIX pwd
    -WINNT chdir
    -AS/400 pwd
  • The -SYSTEM and ! operating system commands have the advantage of not checking which operating system is in use, so when using multiple operating systems where a particular command is the same, for example, the DIR command is the same on Windows and OpenVMS, the -SYSTEM or ! operating system command can simplify coding effort.

Change Directory Operating System Command

The change directory command, which is the cd command on all platforms except OpenVMS (where it is the SET DEFAULT command), may not appear to operate as expected if a second request issues a -UNIX pwd command. An example is when -UNIX cd /tmp seems to be ignored when issued. Operating system commands operate as separate processes, so when the process exits, environmental properties such as variables no longer exist and any change of directory is undone. This behavior is consistent with the non-persistent behavior of server environments that protect one execution from another.

Due to this behavior, a change directory command is typically used as part of a request to execute multiple operating system commands on a single line. The cd command is issued first, then the desired command is issued, so the commands execute as a group. Applications ported from releases prior to Version 7 Release 1.5 or ported from FOCUS may have been coded previously based on persistent behavior and must now be coded to combine the change directory and one or more operating system commands onto a single line.

Executing Multiple Operating System Commands on a Single Line

Most operating systems allow more than one command on a single line by using special separators or surrounding syntax. Each method varies depending on the operating system. The following are examples using the required syntax for executing (stacking) multiple operating system commands on a single line:

For Windows:

! cmd /c "cd \tmp && chdir && if exist mydata.txt echo got it"
! cmd /c "cd \tmp & chdir & if exist mydata.txt echo got it "
! cd \tmp & chdir & if exist mydata.txt echo got it
! dir mydata & if exist mydata.txt echo got it


! cd /tmp ; pwd ; if [ -f mydata.txt ] ; then echo got it ; fi
! ls mydata.txt ; if [ -f mydata.txt ] ; then echo got it ; fi

For OpenVMS:

! PIPE DELETE mydata.txt;* /Noconfirm > NL: 2> NL:

For IBM i:

! cd /tmp ; pwd ; if [ -f mydata.txt ] ; then echo got it ; fi
! system "DSPLIB QGPL" ; if [ -f mydata.txt ] ; then echo got it ; fi
! ls mydata.txt ; if [ -f mydata.txt ] ; then echo got it ; fi

Note: Native IBM i commands can be stacked with QShell commands if the native portion uses the QShell system command with the native command portion enclosed in double quotes.

Reviewing Command Output

Some operating system commands perform a function and do not display additional output. For example, the following commands do not display any output when the command is executed:

-UNIX cp a.fex b.fex
-DOS copy a.fex b.fex

Other commands return output when the command is executed. For example, the following commands display a list of files in the current directory that ends in fex:

-UNIX ls -l grep fex
-DOS dir *.fex

WebFOCUS does not display operating system command results in the browser. To review the results of an operating system command, you must redirect the output to another file.

For example, the following commands redirect the command output to a file named OUTPUT (which you can review later in an editor):

-UNIX ls -l grep fex > /tmp/output
-DOS dir *.fex > c:\tmp\output