Microsoft KB Archive/70008

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 18:58, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to Shell or Run Another Process with Pascal’s Spawnlp PSS ID Number: Q70008 Article last modified on 03-28-1991 PSS database name: S_PasCal

3.32 4.00

MS-DOS

Summary:

The include file PASEXEC.INC provided with Microsoft Pascal versions 3.32 and 4.00 documents how to spawn to another process (.EXE or .COM) from within a Pascal program. The file PASEXEC.INC can be found on disk 3 for version 4.00 or disk 2 for version 3.32 of Microsoft Pascal.

To spawn (shell or run) to another process requires a call to the external function spawnlp, which is contained within CEXEC.LIB, as shown further below.

Because spawnlp relies on DOS-specific operating system calls, it cannot be used in a program compiled to run under MS OS/2.

This information applies to Microsoft Pascal versions 3.32 and 4.00 for MS-DOS.

More Information:

The function spawnlp is a C function contained within the library CEXEC.LIB. The call (from Pascal) to spawnlp is of the following form:

ReturnCode:=spawnlp(mode,pathname,pathname,arg1, … argn,NULL);

Argument Type Comments ——– —- ——–

ReturnCode Integer Contains a return code if the function call fails. Zero (0) indicates success. mode Integer Can contain the following values: 0 indicates shell _p_overlay is a global variable, which indicates run. pathname ADS pointer Far pointer to a string containing the full path and filename of the process being spawned. arg1…argn ADS pointer A variable number of far pointers indicating the command-line parameters passed to the spawned process. NULL Integer4 Indicates the last argument of the function call. Always has the value of 0.

Below is a program example, PascalSpawn, which first shells to the program Target and then runs to it:

Use the PL compiler as follows to create the files SPAWN.EXE and TARGET.EXE:

PL SPAWN.PAS /link CEXEC.LIB PL TARGET.PAS

SPAWN.PAS

Program PascalSpawn(input,output); const FileName = ‘target.exe’; var _p_overlay [c,extern]:integer; NULL:integer4; i:integer;

function spawnlp : integer [c,varying]; extern; {NOTE: “varying” indicates that a variable number of arguments can be passed to the function}

begin NULL:=0; writeln(‘Shelling to’,Filename); i:=spawnlp(0,ads(FileNamechr(0)), ads(FileNamechr(0)),NULL); if (i = 0) then begin writeln; writeln(‘Successfully returned from the shell!’); writeln; writeln(‘Running to’,Filename); end else begin writeln; writeln(‘Error attempting to shell to’,FileName); end;

i:=spawnlp(_p_overlay,ads(FileNamechr(0)),ads(FileNamechr(0)),NULL); writeln; writeln(‘You should never see this message!’); writeln; writeln(‘Error attempting to run’,FileName); end.

TARGET.PAS

program Target (input,output); begin writeln; writeln(‘In TARGET.EXE’); end.

Copyright Microsoft Corporation 1991.