Lazarus:通过TProcess运行curl的奇怪行为

问题描述 投票:0回答:1

我使用TProcess从Lazarus / FPC应用程序运行'curl':

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;

它总是失败:

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

或任何curl的参数是第一个。用'proc.Parameters.Add'分别添加每个参数都没关系。

同时

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  

按预期从命令行手动执行。

ShellExecute也可以。

通过TProcess运行'curl'怎么了?

curl lazarus freepascal running-other-programs
1个回答
0
投票

您将整个命令行放在一个参数中。分开他们。使用多个parameter.add()语句

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

而且,这是用于短输出的“简单”解决方案。如果输出时间长,它将挂起。最好查看准备好的RunCommand()包装器。

© www.soinside.com 2019 - 2024. All rights reserved.