1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| unit procSymLnk;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,dos,Process;
procedure Ecrire1Lien(Cible,NomLien : string; bRep : boolean);
procedure LancerCommandeDos(strCde : string; bWait,bOutPut : boolean);
procedure EcrireLeLien(Cible,NomLien : string; bRep : boolean);
implementation
procedure Ecrire1Lien(Cible, NomLien: string; bRep: boolean);
// https://pascal.developpez.com/faq/?page=Turbo-Pascal-Generalites#Comment-executer-un-programme-externe
var
CodeErreur :integer;
StrCde : String;
strCommutateur : string;
begin
// création de la commande
if bRep then strCommutateur := '/D';
strCde := 'MkLink ' + strCommutateur + ' ' + '"' + NomLien + '" "' + Cible + '"';
SwapVectors;
Exec(GetEnv('COMSPEC'),strCde);
SwapVectors;
CodeErreur:=doserror;
end;
procedure LancerCommandeDos(strCde: string; bWait, bOutPut: boolean);
// http://wiki.freepascal.org/Executing_External_Programs/fr
var
AProcess : TProcess;
AStringList: TStringList;
begin
AProcess := TProcess.create(nil);
AStringList := TStringList.Create;
AProcess.CommandLine := strCde;
AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
AProcess.Execute;
AStringList.LoadFromStream(AProcess.Output);
AStringList.SaveToFile('output.txt');
AStringList.free;
AProcess.Free;
end;
procedure EcrireLeLien(Cible, NomLien: string; bRep: boolean);
Var
StrCde : String;
strCommutateur : string;
begin
if bRep then strCommutateur := '/D';
strCde := 'MkLink ' + strCommutateur + ' ' + '"' + NomLien + '" "' + Cible + '"';
LancerCommandeDos(strCde,true,true);
end;
end. |
Partager