Lazarus

Programming => General => Topic started by: laznewb on February 14, 2020, 05:49:41 pm

Title: [SOLVED]Issue with running an executable with parameters
Post by: laznewb on February 14, 2020, 05:49:41 pm
Hi,

I have a program which runs OpenSSL with a few different parameters. Here is the code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   hProcess : TProcess;
  4. begin
  5.   hProcess := TProcess.Create(nil);
  6.   hProcess.Executable := 'C:\OPENSSL\bin\openssl';
  7.   hprocess.Parameters.Add('aes-256-cbc');
  8.   hprocess.Parameters.Add('-a');
  9.   hprocess.Parameters.Add('-in C:\Users\SamSmith\secrets.txt');
  10.   hprocess.Parameters.Add('-out C:\Users\SamSmith\secrets.txt.enc');
  11.   hprocess.Parameters.Add('-pass pass:hello123');
  12.   // hProcess.Options := hProcess.Options + [poWaitOnExit, poUsePipes];
  13.   hProcess.Execute;
  14. end;

However, when ran, the program gives the following output:

Quote
unknown option '-in C:\Users\SamSmith\secrets.txt'

If I run this directly from the command line, however, it works without problem:

Code: Pascal  [Select][+][-]
  1. openssl aes-256-cbc -a -in C:\Users\SamSmith\secrets.txt -out C:\Users\SamSmith\secrets.txt.enc -pass pass:hello123

Does anybody know what I'm doing wrong?

Thank you,
Sam
Title: Re: Issue with running an executable with parameters
Post by: WayneSherman on February 14, 2020, 06:35:49 pm
I don't know if it will help, but try the full EXE file name:
Code: Pascal  [Select][+][-]
  1.   hProcess.Executable := 'C:\OPENSSL\bin\openssl.exe';
Title: Re: Issue with running an executable with parameters
Post by: winni on February 14, 2020, 06:40:17 pm
Hi!

Not  one Space (#32) in the parameters!

You  have to split the line ('-in C :\..... ') into two parameters.

And the same with the line ('-out .....').

Winni
Title: Re: Issue with running an executable with parameters
Post by: laznewb on February 14, 2020, 10:06:47 pm
Thanks winni, I didn't know that, it works perfectly fine now.
TinyPortal © 2005-2018