问题描述
我工作的一些code,从蟒蛇执行ping操作,并通过使用AWK只提取的延迟。这是目前我有:
从OS导入系统
L =系统(平安-c 1站点名称| awk的-F ='FNR == 2 {打印SUBSTR($ 4,1,长度($ 4)-3)}')
打印升
的系统()
通话效果很好,但我在终端得到一个输出而不是存储成L值。基本上,例如输出我从code这个特定块获得将
90.3
0
为什么会这样,我将如何去实际存储的值成L?这是我工作的一个更大的东西的一部分,所以preferably我想保持它在本地蟒蛇。
使用的如果你想存储在一个变量输出:
从子进口check_output
L = check_output(平安-c 1站点名称| awk的-F ='FNR == 2 {打印SUBSTR($ 4,1,长度($ 4)-3)}',壳=真)
打印升
相关报道:执行python脚本 后额外的零p> I'm working on some code that performs a ping operation from python and extracts only the latency by using awk. This is currently what I have: The Why does this happen, and how would I go about actually storing that value into l? This is part of a larger thing I'm working on, so preferably I'd like to keep it in native python. Use Related: Extra zero after executing a python script 这篇关于从分析的ping值存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!from os import system
l = system("ping -c 1 sitename | awk -F = 'FNR==2 {print substr($4,1,length($4)-3)}'")
print l
system()
call works fine, but I get an output in terminal rather than the value storing into l. Basically, an example output I'd get from this particular block of code would be90.3
0
subprocess.check_output
if you want to store the output in a variable:from subprocess import check_output
l = check_output("ping -c 1 sitename | awk -F = 'FNR==2 {print substr($4,1,length($4)-3)}'", shell=True)
print l