在项目中,我想使用命令获取进度的输出
docker ps -a --format '{{json .}}'
但是过程错误
"docker ps" accepts no arguments
这是C#代码
var startInfo = new ProcessStartInfo("docker")
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
Arguments = "ps -a --format '{{json .}}'",
WorkingDirectory = workingDirectory
};
var process = Process.Start(startInfo);
终端中的命令运行正常。我像这样在 cmd 中进行测试
cmd /c "docker ps -a --format '{{json .}}'"
它输出与 C# 相同的错误
那么如何解决呢?
谢谢。
对于遇到同样问题的任何人,我找到了解决方案这里
拨打
bash
而不是直接拨打 docker
。docker ps -a --format '{{json .}}'
var startInfo = new ProcessStartInfo("bash")
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
Arguments = "-c \"docker ps -a --format '{{json .}}'\"",
WorkingDirectory = workingDirectory
};
var process = Process.Start(startInfo);