fpredir.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. {
  2. This file is part of the Free Pascal Test Suite
  3. Copyright (c) 1999-2000 by Pierre Muller
  4. Unit to redirect output and error to files
  5. Adapted from code donated to public domain by Schwartz Gabriel 20/03/1993
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. Unit FpRedir;
  13. Interface
  14. {$R-}
  15. {$ifndef Linux}
  16. {$ifndef Unix}
  17. {$S-}
  18. {$endif}
  19. {$endif}
  20. {$ifdef Go32v2}
  21. {$define implemented}
  22. {$endif}
  23. {$ifdef OS2}
  24. {$define shell_implemented}
  25. {$endif}
  26. {$ifdef Windows}
  27. {$define implemented}
  28. {$endif}
  29. {$ifdef linux}
  30. {$define implemented}
  31. {$endif}
  32. {$ifdef BSD}
  33. {$define implemented}
  34. {$endif}
  35. {$ifdef netwlibc}
  36. {$define implemented}
  37. {$endif}
  38. {$ifdef netware_clib}
  39. {$define implemented}
  40. {$endif}
  41. Var
  42. IOStatus : Integer;
  43. RedirErrorOut,RedirErrorIn,
  44. RedirErrorError : Integer;
  45. ExecuteResult : Word;
  46. {------------------------------------------------------------------------------}
  47. procedure InitRedir;
  48. function ExecuteRedir (Const ProgName, ComLine, RedirStdIn, RedirStdOut, RedirStdErr : String) : boolean;
  49. procedure DosExecute(ProgName, ComLine : String);
  50. function MaybeQuoted(const s:string):string;
  51. function ChangeRedirOut(Const Redir : String; AppendToFile : Boolean) : Boolean;
  52. procedure RestoreRedirOut;
  53. procedure DisableRedirOut;
  54. procedure EnableRedirOut;
  55. function ChangeRedirIn(Const Redir : String) : Boolean;
  56. procedure RestoreRedirIn;
  57. procedure DisableRedirIn;
  58. procedure EnableRedirIn;
  59. function ChangeRedirError(Const Redir : String; AppendToFile : Boolean) : Boolean;
  60. procedure RestoreRedirError;
  61. procedure DisableRedirError;
  62. procedure EnableRedirError;
  63. procedure RedirDisableAll;
  64. procedure RedirEnableAll;
  65. { unused in UNIX }
  66. const
  67. UseComSpec : boolean = true;
  68. Implementation
  69. Uses
  70. sysutils,
  71. {$ifdef go32v2}
  72. go32,
  73. {$endif go32v2}
  74. {$ifdef netwlibc}
  75. Libc,
  76. {$endif netwlibc}
  77. {$ifdef netware_clib}
  78. nwserv,
  79. {$endif netware_clib}
  80. {$ifdef Windows}
  81. windows,
  82. {$endif Windows}
  83. {$ifdef unix}
  84. baseunix,
  85. unix,
  86. {$endif unix}
  87. dos;
  88. Const
  89. {$ifdef UNIX}
  90. DirSep='/';
  91. listsep = [';',':'];
  92. exeext = '';
  93. {$else UNIX}
  94. DirSep='\';
  95. listsep = [';'];
  96. exeext = '.exe';
  97. {$endif UNIX}
  98. var
  99. FIN,FOUT,FERR : ^File;
  100. RedirChangedOut,
  101. RedirChangedIn : Boolean;
  102. RedirChangedError : Boolean;
  103. InRedirDisabled,OutRedirDisabled,ErrorRedirDisabled : Boolean;
  104. {*****************************************************************************
  105. Helpers
  106. *****************************************************************************}
  107. function FixPath(const s:string):string;
  108. var
  109. i : longint;
  110. begin
  111. { Fix separator }
  112. for i:=1 to length(s) do
  113. if s[i] in ['/','\'] then
  114. fixpath[i]:=DirSep
  115. else
  116. fixpath[i]:=s[i];
  117. fixpath[0]:=s[0];
  118. end;
  119. function maybequoted(const s:string):string;
  120. var
  121. s1 : string;
  122. i : integer;
  123. quoted : boolean;
  124. begin
  125. quoted:=false;
  126. s1:='"';
  127. for i:=1 to length(s) do
  128. begin
  129. case s[i] of
  130. '"' :
  131. begin
  132. quoted:=true;
  133. s1:=s1+'\"';
  134. end;
  135. ' ',
  136. #128..#255 :
  137. begin
  138. quoted:=true;
  139. s1:=s1+s[i];
  140. end;
  141. else
  142. s1:=s1+s[i];
  143. end;
  144. end;
  145. if quoted then
  146. maybequoted:=s1+'"'
  147. else
  148. maybequoted:=s;
  149. end;
  150. {*****************************************************************************
  151. Dos
  152. *****************************************************************************}
  153. {$ifdef implemented}
  154. var
  155. TempHOut, TempHIn,TempHError : longint;
  156. {
  157. For linux the following functions exist
  158. Function fpdup(oldfile:longint;var newfile:longint):Boolean;
  159. Function fpdup2(oldfile,newfile:longint):Boolean;
  160. Function fpClose(fd:longint):boolean;
  161. }
  162. {$ifdef go32v2}
  163. function dup(fh : longint;var nh : longint) : boolean;
  164. var
  165. Regs : Registers;
  166. begin
  167. Regs.ah:=$45;
  168. Regs.bx:=fh;
  169. MsDos (Regs);
  170. dup:=true;
  171. If (Regs.Flags and fCarry)=0 then
  172. nh:=Regs.Ax
  173. else
  174. dup:=false;
  175. end;
  176. function dup2(fh,nh : longint) : boolean;
  177. var
  178. Regs : Registers;
  179. begin
  180. dup2:=true;
  181. If fh=nh then
  182. exit;
  183. Regs.ah:=$46;
  184. Regs.bx:=fh;
  185. Regs.cx:=nh;
  186. MsDos (Regs);
  187. If (Regs.Flags and fCarry)<>0 then
  188. dup2:=false;
  189. end;
  190. function fpdup(fh:longint):longint;
  191. begin
  192. if not dup(fh,fpdup) then
  193. fpdup:=-1;
  194. end;
  195. function fpdup2(fh,nh:longint):longint;
  196. begin
  197. if dup2(fh,nh) then
  198. fpdup2:=0
  199. else
  200. fpdup2:=-1;
  201. end;
  202. function fpclose(Handle : Longint) : boolean;
  203. var Regs: registers;
  204. begin
  205. Regs.Eax := $3e00;
  206. Regs.Ebx := Handle;
  207. MsDos(Regs);
  208. fpclose:=(Regs.Flags and fCarry)=0;
  209. end;
  210. {$endif def go32v2}
  211. {$ifdef Windows}
  212. Function fpclose(Handle : Longint) : boolean;
  213. begin
  214. { Do we need this ?? }
  215. fpclose:=true;
  216. end;
  217. {$endif}
  218. {$ifdef os2}
  219. Function fpclose (Handle : Longint) : boolean;
  220. begin
  221. { Do we need this ?? }
  222. fpclose:=true;
  223. end;
  224. {$endif}
  225. {$I-}
  226. function FileExist(const FileName : PathStr) : Boolean;
  227. var
  228. f : file;
  229. Attr : word;
  230. begin
  231. Assign(f, FileName);
  232. GetFAttr(f, Attr);
  233. FileExist := DosError = 0;
  234. end;
  235. function CompleteDir(const Path: string): string;
  236. begin
  237. { keep c: untouched PM }
  238. if (Path<>'') and (Path[Length(Path)]<>DirSep) and
  239. (Path[Length(Path)]<>':') then
  240. CompleteDir:=Path+DirSep
  241. else
  242. CompleteDir:=Path;
  243. end;
  244. function LocateExeFile(var FileName:string): boolean;
  245. var
  246. S : AnsiString;
  247. dir,d,n,e : string;
  248. i : longint;
  249. begin
  250. LocateExeFile:=False;
  251. if FileExist(FileName) then
  252. begin
  253. LocateExeFile:=true;
  254. Exit;
  255. end;
  256. Fsplit(Filename,d,n,e);
  257. if (e='') and FileExist(FileName+exeext) then
  258. begin
  259. FileName:=FileName+exeext;
  260. LocateExeFile:=true;
  261. Exit;
  262. end;
  263. S:=sysutils.GetEnvironmentVariable('PATH');
  264. While Length(S)>0 do
  265. begin
  266. i:=1;
  267. While (i<=Length(S)) and not (S[i] in ListSep) do
  268. Inc(i);
  269. Dir:=CompleteDir(Copy(S,1,i-1));
  270. if i<Length(S) then
  271. Delete(S,1,i)
  272. else
  273. S:='';
  274. if FileExist(Dir+FileName) then
  275. Begin
  276. FileName:=Dir+FileName;
  277. LocateExeFile:=true;
  278. Exit;
  279. End;
  280. end;
  281. end;
  282. {............................................................................}
  283. function ChangeRedirOut(Const Redir : String; AppendToFile : Boolean) : Boolean;
  284. begin
  285. ChangeRedirOut:=False;
  286. If Redir = '' then Exit;
  287. Assign (FOUT^, Redir);
  288. If AppendToFile and FileExist(Redir) then
  289. Begin
  290. Reset(FOUT^,1);
  291. Seek(FOUT^,FileSize(FOUT^));
  292. End else Rewrite (FOUT^);
  293. RedirErrorOut:=IOResult;
  294. IOStatus:=RedirErrorOut;
  295. If IOStatus <> 0 then Exit;
  296. {$ifdef Windows}
  297. if SetStdHandle(Std_Output_Handle,FileRec(FOUT^).Handle) then
  298. {$else not Windows}
  299. TempHOut:=fpdup(StdOutputHandle);
  300. fpdup2(FileRec(FOUT^).Handle,StdOutputHandle);
  301. if (TempHOut<>UnusedHandle) and
  302. (StdOutputHandle<>UnusedHandle) then
  303. {$endif not Windows}
  304. begin
  305. ChangeRedirOut:=True;
  306. OutRedirDisabled:=False;
  307. end;
  308. RedirChangedOut:=True;
  309. end;
  310. function ChangeRedirIn(Const Redir : String) : Boolean;
  311. begin
  312. ChangeRedirIn:=False;
  313. If Redir = '' then Exit;
  314. Assign (FIN^, Redir);
  315. Reset(FIN^,1);
  316. RedirErrorIn:=IOResult;
  317. IOStatus:=RedirErrorIn;
  318. If IOStatus <> 0 then Exit;
  319. {$ifdef Windows}
  320. if SetStdHandle(Std_Input_Handle,FileRec(FIN^).Handle) then
  321. {$else not Windows}
  322. TempHIn:=fpdup(StdInputHandle);
  323. fpdup2(FileRec(FIn^).Handle,StdInputHandle);
  324. if (TempHIn<>UnusedHandle) and
  325. (StdInputHandle<>UnusedHandle) then
  326. {$endif not Windows}
  327. begin
  328. ChangeRedirIn:=True;
  329. InRedirDisabled:=False;
  330. end;
  331. RedirChangedIn:=True;
  332. end;
  333. function ChangeRedirError(Const Redir : String; AppendToFile : Boolean) : Boolean;
  334. begin
  335. ChangeRedirError:=False;
  336. If Redir = '' then Exit;
  337. Assign (FERR^, Redir);
  338. If AppendToFile and FileExist(Redir) then
  339. Begin
  340. Reset(FERR^,1);
  341. Seek(FERR^,FileSize(FERR^));
  342. End else Rewrite (FERR^);
  343. RedirErrorError:=IOResult;
  344. IOStatus:=RedirErrorError;
  345. If IOStatus <> 0 then Exit;
  346. {$ifdef Windows}
  347. if SetStdHandle(Std_Error_Handle,FileRec(FERR^).Handle) then
  348. {$else not Windows}
  349. TempHError:=fpdup(StdErrorHandle);
  350. fpdup2(FileRec(FERR^).Handle,StdErrorHandle);
  351. if (TempHError<>UnusedHandle) and
  352. (StdErrorHandle<>UnusedHandle) then
  353. {$endif not Windows}
  354. begin
  355. ChangeRedirError:=True;
  356. ErrorRedirDisabled:=False;
  357. end;
  358. RedirChangedError:=True;
  359. end;
  360. procedure RestoreRedirOut;
  361. begin
  362. If not RedirChangedOut then Exit;
  363. {$ifdef Windows}
  364. SetStdHandle(Std_Output_Handle,StdOutputHandle);
  365. {$else not Windows}
  366. fpdup2(TempHOut,StdOutputHandle);
  367. {$endif not Windows}
  368. Close (FOUT^);
  369. fpclose(TempHOut);
  370. RedirChangedOut:=false;
  371. end;
  372. {............................................................................}
  373. procedure RestoreRedirIn;
  374. begin
  375. If not RedirChangedIn then Exit;
  376. {$ifdef Windows}
  377. SetStdHandle(Std_Input_Handle,StdInputHandle);
  378. {$else not Windows}
  379. fpdup2(TempHIn,StdInputHandle);
  380. {$endif not Windows}
  381. Close (FIn^);
  382. fpclose(TempHIn);
  383. RedirChangedIn:=false;
  384. end;
  385. {............................................................................}
  386. procedure DisableRedirIn;
  387. begin
  388. If not RedirChangedIn then Exit;
  389. If InRedirDisabled then Exit;
  390. {$ifdef Windows}
  391. SetStdHandle(Std_Input_Handle,StdInputHandle);
  392. {$else not Windows}
  393. fpdup2(TempHIn,StdInputHandle);
  394. {$endif not Windows}
  395. InRedirDisabled:=True;
  396. end;
  397. {............................................................................}
  398. procedure EnableRedirIn;
  399. begin
  400. If not RedirChangedIn then Exit;
  401. If not InRedirDisabled then Exit;
  402. {$ifdef Windows}
  403. SetStdHandle(Std_Input_Handle,FileRec(FIn^).Handle);
  404. {$else not Windows}
  405. fpdup2(FileRec(FIn^).Handle,StdInputHandle);
  406. {$endif not Windows}
  407. InRedirDisabled:=False;
  408. end;
  409. {............................................................................}
  410. procedure DisableRedirOut;
  411. begin
  412. If not RedirChangedOut then Exit;
  413. If OutRedirDisabled then Exit;
  414. {$ifdef Windows}
  415. SetStdHandle(Std_Output_Handle,StdOutputHandle);
  416. {$else not Windows}
  417. fpdup2(TempHOut,StdOutputHandle);
  418. {$endif not Windows}
  419. OutRedirDisabled:=True;
  420. end;
  421. {............................................................................}
  422. procedure EnableRedirOut;
  423. begin
  424. If not RedirChangedOut then Exit;
  425. If not OutRedirDisabled then Exit;
  426. {$ifdef Windows}
  427. SetStdHandle(Std_Output_Handle,FileRec(FOut^).Handle);
  428. {$else not Windows}
  429. fpdup2(FileRec(FOut^).Handle,StdOutputHandle);
  430. {$endif not Windows}
  431. OutRedirDisabled:=False;
  432. end;
  433. {............................................................................}
  434. procedure RestoreRedirError;
  435. begin
  436. If not RedirChangedError then Exit;
  437. {$ifdef Windows}
  438. SetStdHandle(Std_Error_Handle,StdErrorHandle);
  439. {$else not Windows}
  440. fpdup2(TempHError,StdErrorHandle);
  441. {$endif not Windows}
  442. Close (FERR^);
  443. fpclose(TempHError);
  444. RedirChangedError:=false;
  445. end;
  446. {............................................................................}
  447. procedure DisableRedirError;
  448. begin
  449. If not RedirChangedError then Exit;
  450. If ErrorRedirDisabled then Exit;
  451. {$ifdef Windows}
  452. SetStdHandle(Std_Error_Handle,StdErrorHandle);
  453. {$else not Windows}
  454. fpdup2(TempHError,StdErrorHandle);
  455. {$endif not Windows}
  456. ErrorRedirDisabled:=True;
  457. end;
  458. {............................................................................}
  459. procedure EnableRedirError;
  460. begin
  461. If not RedirChangedError then Exit;
  462. If not ErrorRedirDisabled then Exit;
  463. {$ifdef Windows}
  464. SetStdHandle(Std_Error_Handle,FileRec(FErr^).Handle);
  465. {$else not Windows}
  466. fpdup2(FileRec(FERR^).Handle,StdErrorHandle);
  467. {$endif not Windows}
  468. ErrorRedirDisabled:=False;
  469. end;
  470. {............................................................................}
  471. function ExecuteRedir (Const ProgName, ComLine, RedirStdIn, RedirStdOut, RedirStdErr : String) : boolean;
  472. {$ifdef Windows}
  473. var
  474. mode,modebefore : word;
  475. {$endif Windows}
  476. Begin
  477. {$ifdef Windows}
  478. GetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)), @modebefore);
  479. {$endif Windows}
  480. RedirErrorOut:=0; RedirErrorIn:=0; RedirErrorError:=0;
  481. ExecuteResult:=0;
  482. IOStatus:=0;
  483. if RedirStdIn<>'' then
  484. ChangeRedirIn(RedirStdIn);
  485. if RedirStdOut<>'' then
  486. ChangeRedirOut(RedirStdOut,false);
  487. if RedirStdErr<>'stderr' then
  488. ChangeRedirError(RedirStdErr,false);
  489. DosExecute(ProgName,ComLine);
  490. RestoreRedirOut;
  491. RestoreRedirIn;
  492. RestoreRedirError;
  493. ExecuteRedir:=(IOStatus=0) and (RedirErrorOut=0) and
  494. (RedirErrorIn=0) and (RedirErrorError=0) and
  495. (ExecuteResult=0);
  496. {$ifdef Windows}
  497. // restore previous mode
  498. GetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)), @mode);
  499. //mode:=mode or ENABLE_MOUSE_INPUT;
  500. SetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)), modebefore);
  501. {$endif Windows}
  502. End;
  503. {............................................................................}
  504. procedure RedirDisableAll;
  505. begin
  506. If RedirChangedIn and not InRedirDisabled then
  507. DisableRedirIn;
  508. If RedirChangedOut and not OutRedirDisabled then
  509. DisableRedirOut;
  510. If RedirChangedError and not ErrorRedirDisabled then
  511. DisableRedirError;
  512. end;
  513. {............................................................................}
  514. procedure RedirEnableAll;
  515. begin
  516. If RedirChangedIn and InRedirDisabled then
  517. EnableRedirIn;
  518. If RedirChangedOut and OutRedirDisabled then
  519. EnableRedirOut;
  520. If RedirChangedError and ErrorRedirDisabled then
  521. EnableRedirError;
  522. end;
  523. procedure InitRedir;
  524. begin
  525. end;
  526. {$else not implemented}
  527. {*****************************************************************************
  528. Fake
  529. *****************************************************************************}
  530. {$IFDEF SHELL_IMPLEMENTED}
  531. {$I-}
  532. function FileExist(const FileName : PathStr) : Boolean;
  533. var
  534. f : file;
  535. Attr : word;
  536. begin
  537. Assign(f, FileName);
  538. GetFAttr(f, Attr);
  539. FileExist := DosError = 0;
  540. end;
  541. function CompleteDir(const Path: string): string;
  542. begin
  543. { keep c: untouched PM }
  544. if (Path<>'') and (Path[Length(Path)]<>DirSep) and
  545. (Path[Length(Path)]<>':') then
  546. CompleteDir:=Path+DirSep
  547. else
  548. CompleteDir:=Path;
  549. end;
  550. function LocateExeFile(var FileName:string): boolean;
  551. var
  552. S : AnsiString;
  553. dir,d,n,e : string;
  554. i : longint;
  555. begin
  556. LocateExeFile:=False;
  557. if FileExist(FileName) then
  558. begin
  559. LocateExeFile:=true;
  560. Exit;
  561. end;
  562. Fsplit(Filename,d,n,e);
  563. if (e='') and FileExist(FileName+exeext) then
  564. begin
  565. FileName:=FileName+exeext;
  566. LocateExeFile:=true;
  567. Exit;
  568. end;
  569. S:=sysutils.GetEnvironmentVariable('PATH');
  570. While Length(S)>0 do
  571. begin
  572. i:=1;
  573. While (i<=Length(S)) and not (S[i] in ListSep) do
  574. Inc(i);
  575. Dir:=CompleteDir(Copy(S,1,i-1));
  576. if i<Length(S) then
  577. Delete(S,1,i)
  578. else
  579. S:='';
  580. if FileExist(Dir+FileName) then
  581. Begin
  582. FileName:=Dir+FileName;
  583. LocateExeFile:=true;
  584. Exit;
  585. End;
  586. end;
  587. end;
  588. function ExecuteRedir (Const ProgName, ComLine, RedirStdIn, RedirStdOut, RedirStdErr: String): boolean;
  589. var
  590. CmdLine2: string;
  591. begin
  592. CmdLine2 := ComLine;
  593. if RedirStdIn <> '' then CmdLine2 := CmdLine2 + ' < ' + RedirStdIn;
  594. if RedirStdOut <> '' then CmdLine2 := CmdLine2 + ' > ' + RedirStdOut;
  595. if RedirStdErr <> '' then
  596. begin
  597. if RedirStdErr = RedirStdOut
  598. then CmdLine2 := CmdLine2 + ' 2>&1'
  599. else CmdLine2 := CmdLine2 + ' 2> ' + RedirStdErr;
  600. end;
  601. DosExecute (ProgName, CmdLine2);
  602. ExecuteRedir := true;
  603. end;
  604. {$ELSE SHELL_IMPLEMENTED}
  605. function ExecuteRedir (Const ProgName, ComLine, RedirStdIn, RedirStdOut, RedirStdErr : String) : boolean;
  606. begin
  607. ExecuteRedir:=false;
  608. end;
  609. function LocateExeFile(var FileName:string): boolean;
  610. begin
  611. LocateExeFile:=false;
  612. end;
  613. {$ENDIF SHELL_IMPLEMENTED}
  614. function ChangeRedirOut(Const Redir : String; AppendToFile : Boolean) : Boolean;
  615. begin
  616. ChangeRedirOut:=false;
  617. end;
  618. procedure RestoreRedirOut;
  619. begin
  620. end;
  621. procedure DisableRedirOut;
  622. begin
  623. end;
  624. procedure EnableRedirOut;
  625. begin
  626. end;
  627. function ChangeRedirIn(Const Redir : String) : Boolean;
  628. begin
  629. ChangeRedirIn:=false;
  630. end;
  631. procedure RestoreRedirIn;
  632. begin
  633. end;
  634. procedure DisableRedirIn;
  635. begin
  636. end;
  637. procedure EnableRedirIn;
  638. begin
  639. end;
  640. function ChangeRedirError(Const Redir : String; AppendToFile : Boolean) : Boolean;
  641. begin
  642. ChangeRedirError:=false;
  643. end;
  644. procedure RestoreRedirError;
  645. begin
  646. end;
  647. procedure DisableRedirError;
  648. begin
  649. end;
  650. procedure EnableRedirError;
  651. begin
  652. end;
  653. procedure RedirDisableAll;
  654. begin
  655. end;
  656. procedure RedirEnableAll;
  657. begin
  658. end;
  659. procedure InitRedir;
  660. begin
  661. end;
  662. {$endif not implemented}
  663. {............................................................................}
  664. procedure DosExecute(ProgName, ComLine : String);
  665. {$ifdef HASAMIGA}
  666. begin
  667. Dos.Exec(ProgName, ComLine);
  668. end;
  669. {$else}
  670. {$ifdef Windows}
  671. var
  672. StoreInherit : BOOL;
  673. {$endif Windows}
  674. {$ifdef UNIX}
  675. var
  676. s : cint;
  677. {$endif}
  678. Begin
  679. SwapVectors;
  680. {$ifdef UNIX}
  681. IOStatus:=0;
  682. {We need to use fpsystem to get wildcard expansion and avoid being
  683. interrupted by ctrl+c (SIGINT).
  684. But used wifexited and wexitstatus functions
  685. to correctly interpret fpsystem reutrn value }
  686. s:=fpsystem(MaybeQuoted(FixPath(Progname))+' '+Comline);
  687. if wifexited(s) then
  688. ExecuteResult:=wexitstatus(s)
  689. else
  690. begin
  691. ExecuteResult:=word(s);
  692. IOStatus:=(-ExecuteResult) and $7f;
  693. ExecuteResult:=((-ExecuteResult) and $ff00) shr 8;
  694. end;
  695. {$else}
  696. {$ifdef Windows}
  697. StoreInherit:=ExecInheritsHandles;
  698. ExecInheritsHandles:=true;
  699. {$endif Windows}
  700. DosError:=0;
  701. If UseComSpec then
  702. Dos.Exec (Getenv('COMSPEC'),'/C '+MaybeQuoted(FixPath(progname))+' '+Comline)
  703. else
  704. begin
  705. if LocateExeFile(progname) then
  706. Dos.Exec(ProgName,Comline)
  707. else
  708. DosError:=2;
  709. end;
  710. {$ifdef Windows}
  711. ExecInheritsHandles:=StoreInherit;
  712. {$endif Windows}
  713. IOStatus:=DosError;
  714. ExecuteResult:=DosExitCode;
  715. {$endif}
  716. SwapVectors;
  717. {$ifdef CPU86}
  718. { reset the FPU }
  719. {$asmmode att}
  720. asm
  721. fninit
  722. end;
  723. {$endif CPU86}
  724. End;
  725. {$endif HASAMIGA}
  726. {*****************************************************************************
  727. Initialize
  728. *****************************************************************************}
  729. initialization
  730. New(FIn); New(FOut); New(FErr);
  731. finalization
  732. Dispose(FIn); Dispose(FOut); Dispose(FErr);
  733. End.