Skip to content

Commit

Permalink
luasubprocess: runcommand also return errorstring and exitstatus
Browse files Browse the repository at this point in the history
  • Loading branch information
dazedcat19 committed Oct 1, 2020
1 parent 92cecfd commit c67b353
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions baseunits/lua/LuaSubprocess.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,42 @@ function subprocess_create(L: Plua_State): Integer; cdecl;
Result := 1;
end;

Const
ForbiddenOptions = [poRunSuspended,poWaitOnExit];

function _runcommand(L:Plua_State;Options:TProcessOptions=[];SWOptions:TShowWindowOptions=swoNone): Integer;
var
args: array of string;
r: Boolean;
s: String;
i: Integer;
p : TProcess;
i,
ExitStatus : integer;
OutputString : String;
ErrorString : String;
presult: Boolean;
begin
SetLength(args,lua_gettop(L)-1);
s:='';
r:=False;
for i:=2 to lua_gettop(L) do
args[i-2] := luaToString(L,i);
r := process.RunCommand(luaToString(L,1), args, s, Options, SWOptions);
lua_pushboolean(L, r);
lua_pushstring(L, s);
Result:=2;
OutputString:='';
ErrorString:='';
ExitCode:=0;
presult:=False;

p:=DefaultTProcess.create(nil);
if Options<>[] then
P.Options:=Options - ForbiddenOptions;
P.ShowWindow:=SwOptions;
p.Executable:=luaToString(L,1);
if lua_gettop(L)>1 then
for i:=2 to lua_gettop(L) do
p.Parameters.Add(luaToString(L,i));
try
presult:=p.RunCommandLoop(OutputString,ErrorString,ExitStatus)=0;
finally
p.free;
end;
if exitstatus<>0 then presult:=false;
lua_pushboolean(L,presult);
lua_pushstring(L,OutputString);
lua_pushstring(L,ErrorString);
lua_pushinteger(L,ExitStatus);
Result:=4;
end;

function subprocess_runcommand(L: Plua_State): Integer; cdecl;
Expand Down

0 comments on commit c67b353

Please sign in to comment.