test.py:

  1. #coding=utf-
  2. import subprocess
  3. compilePopen = subprocess.Popen('gcc haha',shell=True,stderr=subprocess.PIPE)
  4. compilePopen.wait()
  5. print('the status code is:',compilePopen.returncode)
  6. with open('log','w') as object:
  7. object.write(compilePopen.stderr.read())

test.sh:

  1. #!/bin/bash
  2. while read str; do
  3. echo $str
  4. done <readme.txt
  1. sudo chmod +x test.sh
    ./test.sh

输出:

  1. #coding=utf-
  2. import subprocess
  3. compilePopen = subprocess.Popen('gcc haha',shell=True,stderr=subprocess.PIPE)
  4. compilePopen.wait()
  5. print('the status code is:',compilePopen.returncode)
  6. with open('log','w') as object:
  7. object.write(compilePopen.stderr.read())

shell 按行读取文件的内容的更多相关文章

  1. Shell按行读取文件的3种方法

    Shell按行读取文件的方法有很多,常见的三种方法如下: 要读取的文件: [root@mini05 -]# cat file.info 写法一: [root@mini05 -]# cat read1. ...

  2. shell按行读取文件

    这工作小半年了发现以前学的那么多流弊技能都不怎么用,倒是shell用的很多,自己已经从shell小菜鸟一步步走过来,已经要变成大菜鸟=.= 经常需要用shell按行读取配置文件,自己在上面踩了很多坑, ...

  3. shell 按行读取文件

    #!/bin/bash count= //赋值语句,不加空格 cat test | while read line //cat 命令的输出作为read命令的输入,read读到的值放在line中 do ...

  4. C++/Php/Python/Shell 程序按行读取文件或者控制台

    写程序经常需要用到从文件或者标准输入中按行读取信息,这里汇总一下.方便使用 1. C++ 读取文件 #include<stdio.h> #include<string.h> i ...

  5. C++/Php/Python/Shell 程序按行读取文件或者控制台方法总结。

    C++/Php/Python/Shell 程序按行读取文件或者控制台方法总结. 一.总结 C++/Php/Python/Shell 程序按行读取文件或者控制台(php读取标准输入:$fp = fope ...

  6. shell总结:读取文件、参数、if、分割字符串、数组长度、空文件、变量赋值、多进程、按行切割文件、查看线程

    Reference: http://saiyaren.iteye.com/blog/1943207 1.     Shell  读取文件和写文件 for line in $(<top30000. ...

  7. Python跳过第一行读取文件内容

    Python编程时,经常需要跳过第一行读取文件内容.比较容易想到是为每行设置一个line_num,然后判断line_num是否为1,如果不等于1,则进行读取操作.相应的Python代码如下: inpu ...

  8. android按行读取文件内容的几个方法

    一.简单版 import java.io.FileInputStream; void readFileOnLine(){ String strFileName = "Filename.txt ...

  9. shell脚本,按行读取文件的几种方法。

    第一种方法用while实现按读取文件.[root@localhost wyb]# cat a.txt 第一行 aaaaaa 第二行 bbbbbb 第三行 cccccc 第四行 dddddd 第五行 e ...

随机推荐

  1. MySQL建表 TIMESTAMP 类型字段问题

    Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT ...

  2. JavaScript实现RSA加解密

    在GitHub上找到jsencrypt.js对RSA加解密的工具文件,地址分别是:https://github.com/travist/jsencrypt和https://github.com/ope ...

  3. MongoDB3.2新特性之文档验证

    官方参考: https://docs.mongodb.org/master/core/document-validation/ 文档验证是3.2的重要新特性,添加验证条件的情形无非两种,一是在创建集合 ...

  4. Backup &recovery备份和还原

    实践版本:MySQL5.7 备份类型(backup type)物理和逻辑备份(Physical Versus Logical Backup)        物理备份是指直接复制存储数据库内容的目录和文 ...

  5. nginx----------前端写了一套带有vue路由的的功能。放到nginx配置的目录下以后,刷新会报404未找到。

    1. 这是根据实际情况来写的. location /h5/activity/wechat/ {            index  index.html index.htm index.php;    ...

  6. RNA-seq标准化

    你的 heatmap 可能用错数据了 (组间表达量标准化) http://www.genek.tv/article/24 RNA-seq的标准化方法罗列 https://www.jianshu.com ...

  7. CSS制作渐变背景色

    <style type="text/css"> #grad1 { background: -webkit-linear-gradient(#C2F2F0,#); /* ...

  8. Dev TreeList 某一列进行格式化显示

    private void treeList1_GetNodeDisplayValue(object sender, GetNodeDisplayValueEventArgs e)        {   ...

  9. 融云亮相GDG谷歌女性开发者大会 揭秘IMSDK网络优化策略

    4 月 20 日,冷雨阻碍不了天津GDG谷歌女性开发者大会的热烈召开,一众开发者.架构师和科技公司创业者云集一堂,就女性开发者的技术.职场.人生多方面话题展开深入探讨.活动由GDG (谷歌开发者社区) ...

  10. JS 全选、全不选、反选

    function checkReturn(obj) { var objIds = obj.value; //当没有选中某个子复选框时,checkboxall取消选中 if (!$("#sub ...