【转】./a.out 2>&1 > outfile
原文网址:http://www.cnblogs.com/zhaoyl/archive/2012/10/22/2733418.html
APUE 3.5关于重定向有个容易迷惑人的问题:
./a.out > outfile 2>&1
./a.out 2>&1 > outfile
问两者区别。自己试了下,

int main(){
printf("output to stdio\n");
fprintf(stderr,"output to stderr\n");
return 1;
}
// 结果如下:
$ ./a.out > outfile 2>&1
$ cat outfile
output to stderr
output to stdin
$ ./a.out 2>&1 > outfile
output to stderr

原因是:
由于bash从左往右处理,在./a.out > outfile的时候,将a.out的fd 1定向到了outfile文件的fd上,然后才遇到2>&1,这时再将a.out的文件描述符2定向到文件描述符1上,这样stderr和stdout,就都到outfile上了。
而下面一个则不然,先遇到2>&1,这时将a.out的文件描述符2定向到文件描述符1上,1是终端。再遇到 > outfile,这时将a.out的文件描述符1重定向到outfile这个文件。结果是,标准错误输出到了屏幕,而标准输出定向到了outfile!
也可以写shell脚本测试一下:

#!/bin/bash
touch output
test () {
echo "before error.."
someerror #错误,变量或命令未定义
echo "after error ..."
}
test 2>&1 >output

【转】./a.out 2>&1 > outfile的更多相关文章
- web安全之sqlload_file()和into outfile()
load_file() 条件:要有file_priv权限 知道文件的绝对路径 能使用union 对web目录有读权限 如果过滤啦单引号,则可以将函数中的字符进行hex编码 步骤: 1.读/etc/in ...
- mysql load data infile的使用 和 SELECT into outfile备份数据库数据
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt' [REPLACE | IGNORE] INTO TABLE t ...
- 快速的mysql导入导出数据(load data和outfile)
1.load data: ***实际应用:把日志生成的xls文件load到MySQL中: mysql_cmd = "iconv -c -f utf-8 -t gbk ./data/al_ve ...
- mysql dumpfile与outfile函数的区别
一直以为两个函数作用是相同的 经过简单测试发现还是有些区别的 如下表admin mysql> select * from admin; +-----+-----------+-- ...
- Sqli-LABS通关笔录-7[文件写入函数Outfile]
该关卡最主要的就是想要我们学习到Outfile函数(文件写入函数)的使用. 通过源代码我们很容易的写出了payload.倘若我们一个个去尝试的话,说实话,不容易. http://127.0.0.1/s ...
- into outfile 生成sql脚本
select concat('insert into t_dm_stage(STAGE_ID,STAGE_NAME) values(',STAGE_ID,',','\'',STAGE_NAME,'\' ...
- Mysql备份--mysqldump&outfile
1.备份工具mysqldump 客户端和服务器端都能用select outfile 只能写到服务器端 2.按表单位备份 a.单个表备份 mysqldump -uusername -p database ...
- 【转】linux下a.out >outfile 2>&1重定向问题
原文网址:http://blog.chinaunix.net/uid-25909722-id-2912890.html 转自:http://blog.chinaunix.net/space.php?u ...
- MySQL select into outfile用法
select into outfile用法 SELECT ... FROM TABLE_A INTO OUTFILE "/path/to/file" FIELDS TERMINAT ...
随机推荐
- linux源代码阅读笔记 fork和execve的区别
1. man exec就可以知到: The exec() family of functions replaces the current process image with a new proce ...
- Python-aiohttp百万并发
http://www.aikaiyuan.com/10935.html 本文将测试python aiohttp的极限,同时测试其性能表现,以分钟发起请求数作为指标.大家都知道,当应用到网络操作时,异步 ...
- Selenium--cssselector
CSS(即层叠样式表Cascading Stylesheet) Selector来定位(locate)页面上的元素(Elements).Selenium官网的Document里极力推荐使用CS ...
- http://www.cnblogs.com/huangcong/archive/2010/06/14/1757957.html
http://www.cnblogs.com/huangcong/archive/2010/06/14/1757957.html http://www.cnblogs.com/langtianya/a ...
- lintcode:Valid Sudoku 判断数独是否合法
题目: 判断数独是否合法 请判定一个数独是否有效.该数独可能只填充了部分数字,其中缺少的数字用 . 表示. 样例 下列就是一个合法数独的样例. 注意 一个合法的数独(仅部分填充)并不一定是可解的.我们 ...
- python package list
argparse: 解析命令行参数:http://www.cnblogs.com/snow-backup/p/4010751.html logging: 写日志; http://blog.csdn.n ...
- Tomcat处理HTTP请求源码分析(下)
转载:http://www.infoq.com/cn/articles/zh-tomcat-http-request-2 很多开源应用服务器都是集成tomcat作为web container的,而且对 ...
- Mysql 分页语句Limit用法
转载自:http://qimo601.iteye.com/blog/1634748 1.Mysql的limit用法 在我们使用查询语句的时候,经常要返回前几条或者中间某几行数据,这个时候怎么办呢?不用 ...
- Java学习笔记之:Java 接口
一.引言 接口(英文:Interface),在JAVA编程语言中是一个抽象类型,是抽象方法的集合,接口通常以interface来声明.一个类通过继承接口的方式,从而来继承接口的抽象方法. 接口并不是类 ...
- 关于use-default-filters的一个问题
use-default-filters=true 默认行为会自动扫描所有注解