-1
我想重定向一个系统调用输出到文件 ..我想这个..重定向stdout和stderr到一个文件
#include <stdio.h>
int main()
{
system("ls >> temp.txt");
return 0;
}
但这只是工作系统调用 ..如果我把一些其他东西代替ls
,错误输出不重定向到文件..它只是印在console
..
例如
#include <stdio.h>
int main()
{
system("hello >> temp.txt");
return 0;
}
我想错误输出重定向到文件..我怎么能这样做?感谢..
'命令2>&1 >> temp.txt' – devnull 2013-04-30 07:41:07
您还需要重定向标准错误。确切的方式取决于你的shell(可能是bash) - 查找标准错误重定向。 – ugoren 2013-04-30 07:41:28
“我想将系统调用的输出重定向到一个文件中..我试过这个..但是这只对系统调用有效。”*那么,究竟是什么问题呢?听起来像是任务完成。* – Vorac 2013-04-30 08:09:28