Windows cmd将子命令输出redirect到文件

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

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

完全没有。 但是,如果我删除引号内的redirect(忽略我的应用程序输出),它会执行。 所以问题是,如何redirect子命令的标准输出?

根据你对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 -oa 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!