0

I run the 'curl' from Lazarus/FPC application using TProcess like:

proc := TProcess.Create(nil);
proc.Executable:= 'E:\sendfileemail\curl.exe';
proc.CurrentDirectory:= 'E:\sendfileemail';
proc.Parameters.Add('--upload-file d:\29\ZP_1_2019.eml --url smtps://smtp.yandex.ru:465 --ssl-reqd --mail-from xxxx@yandex.ru --mail-rcpt yyyy@yandex.ru --user zzzz@yandex.ru:password --insecure');
proc.Options := proc.Options + [poWaitOnExit, poUsePipes, poStderrToOutPut];
proc.Execute;
AStringList := TStringList.Create;
AStringList.LoadFromStream(proc.Output);
AStringList.SaveToFile('output.txt');
AStringList.Free;
proc.Free;

It's always failed with:

curl: option --upload-file d:\29\ZP_1_2019.eml: is unknown  
curl: try 'curl --help' or 'curl --manual' for more information

or whatever curl's parameter was first.
Adding each parameter separately with 'proc.Parameters.Add' doesn't matter.

At the same time

E:\sendfileemail\curl.exe --upload-file d:\29\ZP_1_2019.eml --url smtps://smtp.yandex.ru:465 --ssl-reqd --mail-from xxxx@yandex.ru --mail-rcpt yyyy@yandex.ru --user zzzz@yandex.ru:password --insecure  

executed as expected from command line manually.

ShellExecute also work.

What's wrong with running 'curl' via TProcess?

gapsf
  • 634
  • 4
  • 8

1 Answers1

1

You put the whole commandline in one parameter. Separate them out. using multiple parameters.add() statements

proc.Parameters.Add('--upload-file');
proc.Parameters.Add('d:\29\ZP_1_2019.eml');

etc

Also, this is the "simple" solution for short output. If you have long output it will hang. Might be best to look at the prepared RunCommand() wrappers.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89