[英]How to run AWS CLI command from .NET Core
Is it possible to run aws cli command from .NET Core app?是否可以从 .NET Core 应用程序运行 aws cli 命令? I need automatically sync content of folder with S3.
我需要自动将文件夹的内容与 S3 同步。 I use AWS SDK for other setup, but AWS SDK not contains s3 sync method.
我使用 AWS SDK 进行其他设置,但 AWS SDK 不包含 s3 同步方法。
I tried create .NET Core Console and create.bat file with (for the test only check an version of aws)我尝试使用创建 .NET 核心控制台和 create.bat 文件(仅用于测试,检查 aws 的版本)
aws --version
PAUSE
And start from .NET并从 .NET 开始
string pathToRun = @"C:\Users\Adam\source\repos\StaticWeb\StaticWeb\run.bat";
Process p = new Process();
p.StartInfo.FileName = pathToRun;
// Run the process and wait for it to complete
p.Start();
p.WaitForExit();
Error错误
aws --version 'aws' is not recognized as an internal or external command, operable program or batch file. aws --version 'aws' 不是内部或外部命令、可运行程序或批处理文件。
If I start manual run.bat, it works properly.如果我启动手动 run.bat,它可以正常工作。
I have installed AWS CLI 32 bit and 64 bit on my computer.我已经在我的计算机上安装了 AWS CLI 32 位和 64 位。
I've found the solution, so I have replaced aws keywork with path to aws cli.我找到了解决方案,所以我用 aws cli 的路径替换了 aws keywork。 I don't need.bat anymore.
我不再需要 .bat 了。
string command = $"/C start \"\" \"C:/Program Files/Amazon/AWSCLIV2/aws.exe\" --version";
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "cmd.exe";
info.Arguments = command;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
var process = new Process();
process.StartInfo = info;
process.Start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.