怎样才能把标准输入和标准异常同时重定向到一个文件,这样看起来像是cmd的完整输出。
怎样才能把标准输入和标准错误同时重定向到一个文件,这样看起来像是cmd的完整输出。。。
怎样才能把标准输入和标准错误同时重定向到一个文件,这样看起来像是cmd的完整输出。。。
code=c] if (freopen(shellFileName, "w", stdout)==NULL)
return 0;
if (freopen(shellFileName, "w", stderr)==NULL)
return 0;
//这样子还是好象只重定向了一个。。。
[/code]
------解决方案--------------------
我只注意到2个头像不一样...
------解决方案--------------------
没事别用stderr
------解决方案--------------------
cmd >log 2>&1
------解决方案--------------------
command &>filename 或者楼上那种
------解决方案--------------------
------解决方案--------------------
The freopen() function opens the file whose name is the string pointed
to by path and associates the stream pointed to by stream with it. The
original stream (if it exists) is closed. The mode argument is used
just as in the fopen() function. The primary use of the freopen()
function is to change the file associated with a standard text stream
怎样才能把标准输入和标准错误同时重定向到一个文件,这样看起来像是cmd的完整输出。。。
code=c] if (freopen(shellFileName, "w", stdout)==NULL)
return 0;
if (freopen(shellFileName, "w", stderr)==NULL)
return 0;
//这样子还是好象只重定向了一个。。。
[/code]
------解决方案--------------------
我只注意到2个头像不一样...
------解决方案--------------------
没事别用stderr
------解决方案--------------------
cmd >log 2>&1
------解决方案--------------------
command &>filename 或者楼上那种
------解决方案--------------------
#include <iostream>
#include <fstream>
int main()
{
ofstream ofs("output.txt");
streambuf *sb = ofs.rdbuf();
cout.ios::rdbuf(sb);
cerr.ios::rdbuf(sb);
cout << "cout" << endl;
cerr << "cerr" << endl;
return 0;
}
------解决方案--------------------
The freopen() function opens the file whose name is the string pointed
to by path and associates the stream pointed to by stream with it. The
original stream (if it exists) is closed. The mode argument is used
just as in the fopen() function. The primary use of the freopen()
function is to change the file associated with a standard text stream