linux shell fflush,強制shell腳本fflush
I was wondering if it was possible to tell bash that all calls to echo or printf should be followed up by a subsequent call to fflush() on stdout/stderr respectively?
我想知道是否有可能告訴bash所有對echo或printf的調用應該分別跟隨stdout / stderr上的fflush()后續調用?
A quick and dirty solution would be to write my own printf implementation that did this and use it in lieu of either built in, but it occurred to me that I might not need to.
一個快速而骯臟的解決方案是編寫我自己的printf實現,並使用它來代替內置的,但它發生在我身上,我可能不需要。
I'm writing several build scripts that run at once, for debugging needs I really need to see messages that they write in order.
我正在寫幾個同時運行的構建腳本,為了調試需求,我真的需要看到它們按順序寫入的消息。
3 个解决方案
#1
10
If comands use stdio and are connected to a terminal they'll be flushed per line. Otherwise you'll need to use something like stdbuf on commands in a pipe line http://www.pixelbeat.org/programming/stdio_buffering/
如果命令使用stdio並連接到終端,則每行都會刷新它們。否則你需要在管道中的命令上使用stdbuf之類的東西http://www.pixelbeat.org/programming/stdio_buffering/
tl;dr: instead of printf ... try to put to the script stdbuf -o0 printf .., or stdbuf -oL printf ...
tl; dr:而不是printf ...嘗試將腳本stdbuf -o0 printf ..或stdbuf -oL printf ...
#2
1
If you force the file to be read, it seems to cause the buffer to flush. These work for me.
如果強制讀取文件,則似乎會導致緩沖區刷新。這些對我有用。
Either read the data into a useless variable:
將數據讀入無用的變量:
x=$(
Or do a UUOC:
或者做一個UUOC:
cat $logfile > /dev/null
#3
0
Maybe "stty raw" can help with some other tricks for end-of-lines handling. AFAIK "raw" mode turns off line based buffering, at least when used for serial port ("stty raw < /dev/ttyS0").
也許“stty raw”可以幫助一些其他的線端處理技巧。 AFAIK“原始”模式關閉基於行的緩沖,至少在用於串行端口時(“stty raw
linux shell fflush,強制shell腳本fflush相关推荐
- Linux云计算运维之Shell
Linux云计算运维之Shell find 搜索文件名是完全匹配 grep 搜索文件名中的字符串,包含匹配 echo "字符串" : 把字符串输出到控制台 变量分类 : set [ ...
- Linux入门(八)Shell脚本
目录 1.Shell基础 1.1 Shell概述 1.2 Shell脚本的执行方法 1.3 Bash的基本功能 1.3.1 历史命令与命令补全 1.3.2 命令别名与常用快捷键 1.3.3 输入输出重 ...
- linux下各种工具以及shell经验总结
这篇文章是从我多年前的博客倒腾过来的,以后我会继续慢慢更新这篇文章. 1.ls 1)选项-1:所有结果显示为一列 2.grep -c:只显示匹配结果的总行数 grep -c "gejun&q ...
- Linux 命令的执行过程/Shell提示符/alias命令
在 Linux 系统中"一切皆文件",Linux 命令也不例外.那么,当编辑完成 Linux 命令并回车后,系统底层是怎么执行的? 1) 内核层 内核层是 UNIX/Linux 系 ...
- linux read函数_Linux中shell输入ls命令后会系统会发生什么
大家都用过Shell执行一些Linux命令 在命令的背后,到底发生了什么呢,让我们来一起探索 Shell执行主流程 1.Printthe info of reminding 打印提示信息 2.Wait ...
- 10.05 最初对Linux的了解,对Shell的认识
linux的起源:UNIX,代码开源,可以得到源代码,然后自己编译,通过以后可以运行程序. 特点:免费的;兼容POSIX1.0标准;多用户,多任务系统;良好的用户界面;提供了图形界面;支持多种文件系统 ...
- linux计算机中文件意思,shell在计算机语言中一般是啥意思,比如在linux中
2018-11-22 回答 在计算机科学中,shell俗称壳(用来区别于核),是指"提供使用者使用界面"的软件(命令解析器).它类似于dos下的command.com.它接收用户命 ...
- Linux Shell脚本 - 什么是Shell
前言 笔者也是刚接触Linux,很多概念也是一边查资料一边摸索着理解,下面有一些专业性的术语是来源于网络资源. 一些概念笔者本人也还理解得比较模糊,看似简单的东西,深入发掘也会发现并不简单,很多概念都 ...
- linux 运维高级脚本生成器,Linux运维系列,Shell高级脚本自动化编程实战
课程文件目录: Linux自动化运维系列 Shell高级脚本自动化编程实战 [6.1G] ┣━━01.Shell基础概述 [315.1M] ┃ ┣━━1-1 Shell脚本体系概述.mp4 [154. ...
- Linux中使用Msmtp+mutt+shell自动发邮件程序安装说明
Linux中使用Msmtp+mutt+shell自动发邮件程序安装说明 ------by liyoujia 环境: 需要用到mutt 和 msmtp 这两款软件 Mutt:linux初始化安装的时候自 ...
最新文章
- Android动画之帧动画和补间动画
- JavaServlet的方法、主要功能、作用?面试必备!
- nginx python cgi_Python的CGIHTTPServer交互实现详解
- 俄国防部《红星电视台》公布一个俄军“监督”下的大型加密货币矿场
- GitHub 超全机器学习工程师成长路线图,开源两日收获3700+Star!
- 使用Objective-C的+(void)initialize初始化static变量
- 论文出图-Matlab导入txt文件数据并绘图
- No Assembler service found - please make sure that the right jars are in your classpath
- 椭圆形建筑——逸夫演艺中心
- Babylon.js 第28章 多面体
- vue项目使用 Recorder.js 实现录音功能
- Ubuntu16.04发热 CPU/GPU温度比win10高解决方法
- 小白css基础学习记之精灵图
- 守护线程daemon
- 【转帖】NAT在NDIS中间层驱动中的实现
- 2016最新的旅游网站程序CMS系统优点和缺点对比分析
- 二叉排序树基本操作(链表实现)(有错误)
- 计算机组成原理(4)IO
- 销售人员如何寻找客户?
- 2018maya怎么加点_Maya2018新增了哪些共功能? Maya2018新功能全面预览
热门文章
- linux桌面记事本,推荐6款简单实用的手机记事本APP,总有一款适合你的‖APP展览馆...
- Filezilla Xshell SecureFX Win10等无法拖放文件(本地或线上)解决办法
- Redis学习笔记(二):Redis keys 命令
- JDK Required: 'tools.jar' seems to be not in IDEA classpath解决办法
- Nginx:配置 try_files 实现内部重定向
- 判断英语名词可数和不可数
- 对于计算机了解的知识,学电脑应该了解哪些基本知识
- 进入Java世界的第一个程序Hello world
- ipad上怎么打开html文件,ipad HTML文件怎么打开
- Ubuntu 20 更新后突然无法获取IP