Recent

Author Topic: [SOLVED]Issue with running an executable with parameters  (Read 831 times)

laznewb

  • New Member
  • *
  • Posts: 20
[SOLVED]Issue with running an executable with parameters
« 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
« Last Edit: February 14, 2020, 10:07:06 pm by laznewb »

WayneSherman

  • Full Member
  • ***
  • Posts: 243
Re: Issue with running an executable with parameters
« Reply #1 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';

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Issue with running an executable with parameters
« Reply #2 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

laznewb

  • New Member
  • *
  • Posts: 20
Re: Issue with running an executable with parameters
« Reply #3 on: February 14, 2020, 10:06:47 pm »
Thanks winni, I didn't know that, it works perfectly fine now.

 

TinyPortal © 2005-2018