Windows cmd将子命令输出重定向到文件

我正在尝试使用cuda-memcheck调试应用程序。 我想要做的是将输出从我的应用重定向到一个文件,但另一方面,将cuda-memcheck的stdout和stderr重定向到另一个文件。 但我无法得到它的工作。 这个:

cuda-memcheck "app.exe > stdout1.txt" > memcheck.log 2>&1

什么都不做。 但是,如果我删除引号内的重定向(忽略我的应用程序输出),它会执行。 所以问题是,如何重定向子命令的stdout?


根据你对cuda-memcheck的行为的评论,你可以使用下面的命令。

cuda-memcheck --log-file memcheck.log app.exe >app.stdout.txt

编辑

这是我在CentOS上的测试。 它可能适用于Win32控制台应用程序,但不适用于Win32应用程序。

a.cu

#include <iostream>
int main () {
    std::cout<< "hello world to stdout!" <<std::endl;
    std::cerr<< "hello world to stderr!" <<std::endl;
    return 0;
}

编译命令:

$ nvcc -O3 -o a a.cu 

运行命令:

$ cuda-memcheck --log-file mem.log a >a.stdout.log 2>a.stderr.log

结果文件:

$ cat mem.log 
========= CUDA-MEMCHECK
========= ERROR SUMMARY: 0 errors

$ cat a.stdout.log 
hello world to stdout!

$ cat a.stderr.log 
hello world to stderr!
链接地址: http://www.djcxy.com/p/92311.html

上一篇: Windows cmd redirect subcommand output to file

下一篇: Windows redirect stdout and stderr to a file