diff --git a/rtl/win16/dos.pp b/rtl/win16/dos.pp index 04d62b2290..e99544d4f9 100644 --- a/rtl/win16/dos.pp +++ b/rtl/win16/dos.pp @@ -64,7 +64,7 @@ Const { Added to interface so that there is no need to implement it both in dos and sysutils units } -//procedure exec_ansistring(path : string;comline : ansistring); +procedure exec_ansistring(path : string;comline : ansistring); procedure Intr(IntNo: Byte; var Regs: Registers); procedure MsDos(var Regs: Registers); external name 'FPC_MSDOS'; @@ -214,96 +214,49 @@ end; --- Exec --- ******************************************************************************} -const - DOS_MAX_COMMAND_LINE_LENGTH = 126; - -(*procedure exec_ansistring(path : string;comline : ansistring); -type - realptr = packed record - ofs,seg : word; - end; - texecblock = packed record - envseg : word; - comtail : realptr; - firstFCB : realptr; - secondFCB : realptr; - iniStack : realptr; - iniCSIP : realptr; - end; +procedure exec_ansistring(path : string;comline : ansistring); var - execblock : texecblock; - c : ansistring; - p : string; - arg_ofs : integer; - fcb1 : array [0..15] of byte; - fcb2 : array [0..15] of byte; + c: ansistring; + pc: PChar; + p: string; + winexec_result: Word; + m: MSG; begin { create command line } - c:=comline; - if length(c)>DOS_MAX_COMMAND_LINE_LENGTH then - begin - writeln(stderr,'Dos.exec command line truncated to ', - DOS_MAX_COMMAND_LINE_LENGTH,' chars'); - writeln(stderr,'Before: "',c,'"'); - setlength(c, DOS_MAX_COMMAND_LINE_LENGTH); - writeln(stderr,'After: "',c,'"'); - end; p:=path; { allow slash as backslash } DoDirSeparators(p); - if LFNSupport then - GetShortName(p); - { allocate FCB see dosexec code } - arg_ofs:=1; - while (arg_ofs0 then + c:='"'+p+'" '+comline else - LastDosExitCode:=0; -end;*) + c:=p+' '+comline; + pc:=PChar(c); + winexec_result:=WinExec(FarAddr(pc^),SW_SHOW); + if winexec_result<32 then + begin + doserror:=winexec_result; + LastDosExitCode:=0; + end + else + begin + doserror:=0; + { wait until the hinstance terminates } + while GetModuleUsage(winexec_result)>0 do + begin + while PeekMessage(FarAddr(m),0,0,0,1) do + begin + TranslateMessage(FarAddr(m)); + DispatchMessage(FarAddr(m)); + end; + end; + { TODO: is there actually a way to receive the child exit code in win16??? } + LastDosExitCode:=0; + end; +end; procedure exec(const path : pathstr;const comline : comstr); begin -// exec_ansistring(path, comline); + exec_ansistring(path, comline); end;