shell 按行读取文件的内容
test.py:
#coding=utf-
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-
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 按行读取文件的内容的更多相关文章
- Shell按行读取文件的3种方法
Shell按行读取文件的方法有很多,常见的三种方法如下: 要读取的文件: [root@mini05 -]# cat file.info 写法一: [root@mini05 -]# cat read1. ...
- shell按行读取文件
这工作小半年了发现以前学的那么多流弊技能都不怎么用,倒是shell用的很多,自己已经从shell小菜鸟一步步走过来,已经要变成大菜鸟=.= 经常需要用shell按行读取配置文件,自己在上面踩了很多坑, ...
- shell 按行读取文件
#!/bin/bash count= //赋值语句,不加空格 cat test | while read line //cat 命令的输出作为read命令的输入,read读到的值放在line中 do ...
- C++/Php/Python/Shell 程序按行读取文件或者控制台
写程序经常需要用到从文件或者标准输入中按行读取信息,这里汇总一下.方便使用 1. C++ 读取文件 #include<stdio.h> #include<string.h> i ...
- C++/Php/Python/Shell 程序按行读取文件或者控制台方法总结。
C++/Php/Python/Shell 程序按行读取文件或者控制台方法总结. 一.总结 C++/Php/Python/Shell 程序按行读取文件或者控制台(php读取标准输入:$fp = fope ...
- shell总结:读取文件、参数、if、分割字符串、数组长度、空文件、变量赋值、多进程、按行切割文件、查看线程
Reference: http://saiyaren.iteye.com/blog/1943207 1. Shell 读取文件和写文件 for line in $(<top30000. ...
- Python跳过第一行读取文件内容
Python编程时,经常需要跳过第一行读取文件内容.比较容易想到是为每行设置一个line_num,然后判断line_num是否为1,如果不等于1,则进行读取操作.相应的Python代码如下: inpu ...
- android按行读取文件内容的几个方法
一.简单版 import java.io.FileInputStream; void readFileOnLine(){ String strFileName = "Filename.txt ...
- shell脚本,按行读取文件的几种方法。
第一种方法用while实现按读取文件.[root@localhost wyb]# cat a.txt 第一行 aaaaaa 第二行 bbbbbb 第三行 cccccc 第四行 dddddd 第五行 e ...
随机推荐
- ESP8266 RTOS SDK烧写环境构建
简介 esptool是一个Python软件程序,适用于ESP8266等一系列芯片的烧写,灵活高效. 环境构建 在官网下载安装最新2.7版python (linux和os x一般会自带python2.7 ...
- 820板子安装python
1. 需要安装python, 从 python.org上下载版本,我下的是python3.5,网上搜索到的是python2.7的交叉编译过程 和820的结合下. 需要注意,先把820的环境设置好,就是 ...
- Apache2 httpd.conf配置文件中文版详解
Apache2 httpd.conf配置文件中文版详解## 基于 NCSA 服务的配置文件.##这是Apache服务器主要配置文件.#它包含服务器的影响服务器运行的配置指令.#参见以取得关于这些指令的 ...
- 《linux就该这么学》第十一节课: 第九章,网卡绑定与sshd服务
8.4.服务的访问控制列表 TCPwrappers是RHEL7中默认启用的流量监控程序,能够对服务做出允许或拒绝. TCPwrappers服务由两个文件控制: /etc/hosts.allow ...
- Sublime 个人常用快捷键
Sublime 个人常用快捷键 Hot Key Alt + F3 选中文本所以有相同项;同多次Ctrl + D Ctrl + L 选中整行,继续按可继续选 Ctrl + Shift + M 选择括号内 ...
- Unity 属性雷达图
using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(MeshFilter),typeof(Mes ...
- 软件测试之Soot
详情请见:https://github.com/fogmisty/SoftwareTest
- Beyond Compare相同文件为何显示差异
原文地址: http://www.beyondcompare.cc/wenti/wenjian-chayi.html Beyond Compare是一款经典老牌且优秀的专业级文本比较工具,它可以很方便 ...
- 零门槛,包教会。让你在5分钟内使用以太坊ERC20智能合约发行属于自己的空气币
前言 目前区块链是互联网中最最火的风口,没有之一.我周围的很多朋友也加入了“炒币”行列,但很不幸,几乎都被“割韭菜”了.而经过我的几天研究,发现,如果自己要发行一种空气币,简直太简单了.只需要下面几个 ...
- git clone git@github.com:snuglove/ 报错
[root@qc_centos7_5 ~]# git clone git@github.com:snuglove/Job-hunting-related.git Cloning into 'Job-h ...