如何解决如何从 Net Core 3.1 运行 Linux 的命令?
我使用 CentOS 8,为了获得处理器使用百分比,我运行以下命令:
root@locahost.localdomain#/bin/grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}'
1.43863
现在,我尝试实现它以从我的 Net Core 3.1 运行
var info = new ProcessStartInfo();
info.FileName = "/bin/grep";
info.Arguments = "'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}'";
info.RedirectStandardOutput = true;
using (var process = Process.Start(info))
{
var output = process.StandardOutput.ReadToEnd(); // --> this returns empty
}
为什么它返回空?命令已经是一样的了,没有错误但是是空的。
我错过了什么?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。