【转】./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 ...
随机推荐
- Extension Methods
Oftentimes you’ll find yourself using classes you can’t modify. Whether they’re basic data types or ...
- Unity3D脚本中文系列教程(十四)
http://dong2008hong.blog.163.com/blog/static/469688272014032134394/ WWWFrom 类Unity3D脚本中文系列教程(十三)辅助类. ...
- C#的cs文件中Response.Clear();Response.ClearHeaders()的作用
在学习一个CS文件,如下:public partial class GetPic : System.Web.UI.Page{ protected void Page_Load(object se ...
- java基础知识回顾之---java String final类构造方法
/** * String 构造方法学习 * String(byte[ ] bytes):通过byte数组构造字符串对象. * String(byte[] bytes, int offs ...
- Xamarin.Android 入门之:Listview和adapter
一.引言 不管开发什么软件,列表的使用是必不可少的,而本章我们将学习如何使用Xamarin去实现它,以及如何使用自定义适配器.关于xamarin中listview的基础和适配器可以查看官网https: ...
- [翻译] - <Entity Framework> - 直接执行数据库命令
原文:[翻译] - <Entity Framework> - 直接执行数据库命令 纯属学习上的记录, 非专业翻译, 如有错误欢迎指正! 原文地址: http://msdn.microsof ...
- 69. Sqrt(x)
题目: Implement int sqrt(int x). Compute and return the square root of x. 链接: http://leetcode.com/pr ...
- C++:类的创建
类的创建 #include<iostream> #include<cmath> using namespace std; class Complex //声明一个名为Compl ...
- 显示Servlet API主要版本,次要版本以及服务器系统信息
package com.mhb; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Servle ...
- [转]useradd 与adduser的区别
转自:Deit_Aaron的专栏 添加用户:useradd -m 用户名 然后设置密码 passwd 用户名 删除用户:userdel -r 用户名 1. 在root权限下,useradd只是 ...