Link to home
Start Free TrialLog in
Avatar of Rcm
Rcm

asked on

Getting the Errorlevels wich a childprocess returns

Hi,

I'm running a childprocess with the exec command and these programs return an errorlevel.
Is there a way to get these in my Pascal program? (In a batchfile I can ask them with the errorlevel 'function?')
I don't need to return the doserror but the errorlevel.

Function ShellCommand(Command : String) : Integer;
Var
  Redirect        : Boolean;
  OutputTo        : String;
Begin
  Redirect := (Pos('>', Command) <> 0);
  If Redirect Then
    OutputTo := ''
  Else
    OutputTo := ' >nul';
  SwapVectors;
  Exec(GetEnv('COMSPEC'), '/C ' + Command + OutputTo);
  SwapVectors;
  ShellCommand := DosError;
End;

ASKER CERTIFIED SOLUTION
Avatar of AvonWyss
AvonWyss
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial