fpredir.pas 18 KB

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