Lazarus: strange behavior running curl via TProcess

649 views Asked by At

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 [email protected] --mail-rcpt [email protected] --user [email protected]: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 [email protected] --mail-rcpt [email protected] --user [email protected]:password --insecure  

executed as expected from command line manually.

ShellExecute also work.

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

1

There are 1 answers

0
Marco van de Voort On BEST ANSWER

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.