What is the exitcode? (we have exitstatus and exitcode).
RunCommandInDir will execute binary exename with command-line options commands, setting curdir as the current working directory for the command. The Options are taken into consideration (poRunSuspended,poWaitOnExit are removed from the set). The output of the command is captured, and returned in the string OutputString. The function waits for the command to finish, and returns True if the command was started succesfully, False otherwise. In the case where the return value is an integer, it is zero for success, and -1 on error.
If a ExitStatus parameter is specified the exit status of the command is returned in this parameter.
hello,
you can try runcommandindir from process unit :
function RunCommandIndir( const curdir: string; const exename: string; const commands: array of string; out outputstring: string; out exitstatus: Integer; Options: TProcessOptions = [] ):Integer; QuoteRunCommandInDir will execute binary exename with command-line options commands, setting curdir as the current working directory for the command. The Options are taken into consideration (poRunSuspended,poWaitOnExit are removed from the set). The output of the command is captured, and returned in the string OutputString. The function waits for the command to finish, and returns True if the command was started succesfully, False otherwise. In the case where the return value is an integer, it is zero for success, and -1 on error.
If a ExitStatus parameter is specified the exit status of the command is returned in this parameter.
Friendly, J.P
exit /b 7
{$mode delphi}
uses process ;
var ex : integer;
outp:string;
begin
writeln(Runcommandindir('.','cmd.exe',['/c','test1.cmd'],outp,ex)); // returns 0 on success execution, -1 otherwise
writeln(ex); // prints exitstatus.
end.
0
7
I would have thought that ExitStatus would have been set to the value of %ERRORLEVEL% automatically :'(