简体   繁体   English

python - 子进程命令和输出(linux 命令)

[英]python - subprocess command and output (linux command)

I have a command as follows, it gives me the cpu, memory and disk sizes in the linux system.我有一个命令如下,它给了我 linux 系统中的 CPU、内存和磁盘大小。 I want to embed it in python code and get output.我想将它嵌入到 python 代码中并获得输出。

But somehow I could not use escape characters properly and get output.但不知何故,我无法正确使用转义字符并获得输出。 What is the most practical way you use for this?您为此使用的最实用的方法是什么?

echo "CPU `LC_ALL=C top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}'`% RAM `free -m | awk '/Mem:/ { printf("%3.1f%%", $3/$2*100) }'` HDD `df -h /store | awk '/\// {print $(NF-1)}'`"

(We can ignore the echo.) (我们可以忽略回声。)

Thanks.谢谢。

尝试将 ar 放在命令字符串之前,如下所示:

r"CPU `LC_ALL=C top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}'`% RAM `free -m | awk '/Mem:/ { printf("%3.1f%%", $3/$2*100) }'` HDD `df -h /store | awk '/\// {print $(NF-1)}'`"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM