I am a newbie so please be gentle.
I want to unrar a lot of rar archives so i thought to try this with a lazarus program. I copied the tutorial on running external programs mostly. But it always reports :
failed to execute C:\lazarus\unrar\WinRAR\RAR.exe x C:\lazarus\unrar\WinRAR\CleanupUpdCfg.rar
C:\lazarus\unrar\WinRAR\data\ :2
On the windows command prompt the same command line i use in the Tprocess runs fine. Wat am i doing wrong ?
Program unit:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Process;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Log: TMemo;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
cmdline1 : TProcess;
cl : string;
AStringList: TStringList;
begin
cl := '';
cmdline1 := TProcess.Create(nil);
cmdline1.ApplicationName := 'RAR.exe';
cl := 'C:\lazarus\unrar\WinRAR\RAR.exe x C:\lazarus\unrar\WinRAR\CleanupUpdCfg.rar C:\lazarus\unrar\WinRAR\data\';
Log.Append(cl) ;
cmdline1.CommandLine := cl;
cmdline1.Options := cmdline1.Options + [poWaitOnExit, poUsePipes];
// Create the TStringList object.
AStringList := TStringList.Create;
Log.Append('StringList created');
Log.Append('now executing .....');
// Now that AProcess knows what the commandline is
// we will run it.
cmdline1.Execute;
Log.Append('Executed.');
// This is not reached until ppc386 stops running.
// Now read the output of the program we just ran
// into the TStringList.
AStringList.LoadFromStream(cmdline1.Output);
// Save the output to a file.
AStringList.SaveToFile('output.txt');
AStringList.Free;
cmdline1.Free;
end;
initialization
{$I unit1.lrs}
end.
Henk