Recent

Author Topic: tprocess failed to execute rar.exe :2  (Read 7282 times)

HenkNL

  • New member
  • *
  • Posts: 9
tprocess failed to execute rar.exe :2
« on: February 07, 2010, 04:10:52 pm »
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 :
Code: [Select]
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:
Code: [Select]
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
« Last Edit: February 10, 2010, 12:47:43 pm by HenkNL »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9521
  • FPC developer.
Re: tprocess failed to execute rar.exe :2
« Reply #1 on: June 30, 2021, 01:59:11 pm »
Do you get any "deprecated" warnings ? commandline has been deprecated a long time.

Bart

  • Hero Member
  • *****
  • Posts: 4413
    • Bart en Mariska's Webstek
Re: tprocess failed to execute rar.exe :2
« Reply #2 on: June 30, 2021, 02:10:15 pm »
The ":2" at the end of the message means that the system was unable to find the path or file.

Bart

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9521
  • FPC developer.
Re: tprocess failed to execute rar.exe :2
« Reply #3 on: June 30, 2021, 02:14:21 pm »
Just use runcommand to get a string, and assign that to tstringlist.

 

TinyPortal © 2005-2018