您的位置:首页 > 运维架构 > Shell

python调用shell, shell 引用python

2016-07-01 02:41 441 查看
python 调用 shell

get_line_num="wc -l as_uniq_info | awk '{print $1}'" ###get the lines of "as_uniq_info"

line_num = os.popen(get_line_num).read().strip('\n')

get_line_num 作为shell执行的命令,会取得文件as_uniq_info文件的行数

os.popen(get_line_num):执行shell

get_line_num = os.popen(get_line_num).read():调用read,赋值给get_line_num,此时get_line_num中含有一个换行符("\n")。

os.popen(get_line_num).read().strip('\n'):去掉换行符

shell 引用python变量

line_num = os.popen(get_line_num)

引用了python中的get_line_num变量。

python引用shell中值

line_num = os.popen(get_line_num).read()

执行完shell后,通过read()函数,赋值给python中的变量line_num
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: