首页 > 系统服务 > 详细

shell 按行读取文件的内容

时间:2019-04-24 00:23:35      阅读:199      评论:0      收藏:0      [点我收藏+]

 

test.py:

#coding=utf-8
import subprocess
compilePopen = subprocess.Popen(‘gcc haha‘,shell=True,stderr=subprocess.PIPE)
compilePopen.wait()
print(‘the status code is:‘,compilePopen.returncode)
with open(‘log‘,‘w‘) as object:
object.write(compilePopen.stderr.read())

 

test.sh:

#!/bin/bash
while read str; do
    echo $str
done <readme.txt

 

sudo chmod +x test.sh
./test.sh

输出:

#coding=utf-8
import subprocess
compilePopen = subprocess.Popen(‘gcc haha‘,shell=True,stderr=subprocess.PIPE)
compilePopen.wait()
print(‘the status code is:‘,compilePopen.returncode)
with open(‘log‘,‘w‘) as object:
object.write(compilePopen.stderr.read())

 

shell 按行读取文件的内容

原文:https://www.cnblogs.com/sea-stream/p/10759942.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!