SHELL function


Run an executable program asynchronously (as a separate process), while execution of the original application continues uninterrupted.


ProcessId??? = SHELL([HANDLES,] CmdString [, WndStyle])


The SHELL function has the following parts:


The name of the program to execute ("child process"), along with and any required arguments or command-line switches.


A number corresponding to the style of the window in which the child process is to be executed.  If WndStyle is omitted, the program is opened normal with focus, the same as WndStyle = 1.

The following table identifies the values for WndStyle and the resulting style of window:


Window style


Hide window


Normal with focus (default)


Minimized with focus


Maximized with focus


Normal without focus


Minimized without focus

SHELL returns the process id of the child process.  The process id is a 32-bit LONG or DWORD value that identifies the child process, if it's a 32-bit or 64-bit process.  If the process id is zero, the child process is not a 32-bit or 64-bit process, or an error occurred.  Use ERR to detect the success of the SHELL function. The HANDLES option allows the child process to inherit the file handles opened by your program. This affects only Windows handles, not PowerBASIC file identifiers. It is an advanced option, for those who know it works and why they need it.


Child processes run asynchronously, or independently of the program that SHELLs.  So, the child process is, probably, still running after control returns from SHELL to your program.  Also, if your program ends before the child process, the child process will continue to run.

To use internal DOS commands like DIR and COPY, you must run the DOS command processor, passing the DOS command as a parameter.  See the example below.

If the program name in CmdString does not include an explicit path, Windows will search for the file in the following paths: the directory where the current program is located, the default directory, the 32-bit Windows system directory, the 16-bit Windows system directory, the Windows directory, and any directories listed in the PATH environment variable.

See also

ERR, SHELL statement


pid??? = SHELL(MyApp$,1)

pid??? = SHELL(ENVIRON$("COMSPEC") + " /C DIR *.* > filename.txt")