Recent

Author Topic: SOLVED: Exception class 'EProcess', message "Failed to execute :267"  (Read 960 times)

puzzled

  • Newbie
  • Posts: 2
Under Windows 10 I am trying to run ImageMagick on a graphic file.  I use TProcess for this purpose, and put handling of TProcess in its own procedure.  I get the following Debugger Exception Notification:

Project project1 raised exception class 'EProcess' with message:
Failed to execute  : 267
At address 4E68F2


The code, triggered by clicking a button, looks like

procedure TForm1.btnTestClick(Sender: TObject);
var
  MCurrentDirectory: string;
  MExecutable: string;
  MParameters: array of string;
begin
  MCurrentDirectory:= '"C:\Users\puzzled\downloads\graphics stuff\sample images"';
  MExecutable:= '"C:\Program Files\ImageMagick\magick.exe"';
  MParameters:= ['"C:\Users\puzzled\Documents\Lazarus\Resource files\arrow.png"',
                 '-alpha', 'set',
                 '-background', 'none',
                 '-rotate', '-44',
                 '"C:\Users\puzzled\downloads\graphics stuff\processed images\arrow44.png"'];
  TProcessHandling(MCurrentDirectory,
                   MExecutable,
                   MParameters);
end;   

procedure TForm1.TProcessHandling(MCurrentDirectory: string;
                                  MExecutable: string;
                                  MParameters: array of string);
var
  RunProgram: TProcess;
  s:string;
begin
  RunProgram := TProcess.Create(nil);
  RunProgram.CurrentDirectory:=MCurrentDirectory;
  RunProgram.Executable:=MExecutable;
  for s in MParameters do
    RunProgram.Parameters.Add(s);
  // Wait until done
  RunProgram.Options := RunProgram.Options + [poWaitOnExit];
  // Run ImageMagick
  RunProgram.Execute;     <--- Exception takes place here
  Runprogram.Free;
end; }


This DOS command, including double quote marks, works without error when run manually:

"C:\Program Files\ImageMagick\magick.exe" "C:\Users\puzzled\Documents\Lazarus\Resource files\arrow.png" -alpha set -background none -rotate 44 "C:\Users\puzzled\downloads\graphics stuff\processed images\arrow44.png"

Thank you for your guidance
« Last Edit: June 16, 2024, 03:09:31 am by puzzled »

Fibonacci

  • Hero Member
  • *****
  • Posts: 613
  • Internal Error Hunter
Re: Exception class 'EProcess', message "Failed to execute :267"
« Reply #1 on: June 13, 2024, 08:32:28 am »
267 is ERROR_DIRECTORY

Remove all quote marks from MCurrentDirectory, MExecutable and MParameters

Thaddy

  • Hero Member
  • *****
  • Posts: 16196
  • Censorship about opinions does not belong here.
Re: Exception class 'EProcess', message "Failed to execute :267"
« Reply #2 on: June 13, 2024, 08:44:19 am »
nope:
Code: Pascal  [Select][+][-]
  1.   Mparameters.AddStrings( ['"C:\Users\puzzled\Documents\Lazarus\Resource files\arrow.png"',
  2.                  '-alpha', 'set',
  3.                  '-background', 'none',
  4.                  '-rotate', '-44',
  5.                  '"C:\Users\puzzled\downloads\graphics stuff\processed images\arrow44.png"']);
Mparameters is - afaik - not overloaded to accept the strings directly. use AddStrings.
in this case the quotation marks are necessary, but make sure the paths exist.
« Last Edit: June 13, 2024, 08:54:09 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

puzzled

  • Newbie
  • Posts: 2
Re: Exception class 'EProcess', message "Failed to execute :267"
« Reply #3 on: June 13, 2024, 07:20:51 pm »
REMOVING THE DOUBLE QUOTES WAS THE SOLUTION.
(How do I mark this as solved?)

Thank you!


Thaddy

  • Hero Member
  • *****
  • Posts: 16196
  • Censorship about opinions does not belong here.
Re: Exception class 'EProcess', message "Failed to execute :267"
« Reply #4 on: June 13, 2024, 07:50:46 pm »
That can not be right on windows...
keep it open.
If I smell bad code it usually is bad code and that includes my own code.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5759
  • Compiler Developer
Re: Exception class 'EProcess', message "Failed to execute :267"
« Reply #5 on: June 13, 2024, 09:51:53 pm »
That can not be right on windows...

It is right, because TProcess handles the quoting itself. Manually adding quotation marks will mess that up.

 

TinyPortal © 2005-2018