简体   繁体   English

如何将输出重定向到批处理文件中的文件?

[英]How to redirect output to a file in a batch file?

In Windows 7, I have a batch file that runs an exe in the sub-directory of bat file, it first changes current directory to that folder, then runs the exe. 在Windows 7中,我有一个批处理文件在bat文件的子目录中运行exe,它首先将当前目录更改为该文件夹,然后运行exe。 But something goes wrong, I see a console window for a very short time and the program doesn't start. 但出了点问题,我看到一个控制台窗口很短的时间,程序无法启动。 Since the output console is displayed for less than a second, I can't see the error message. 由于输出控制台显示不到一秒钟,我看不到错误消息。

bat file is: bat文件是:

cd /d "%~dp0my_subfolder"
start "" myapplication.exe

How do I redirect the output error message to a text file (the text file will be in the same directory with bat file), so that I can read the error message? 如何将输出错误消息重定向到文本文件(文本文件将与bat文件在同一目录中),以便我可以读取错误消息? What command should I add to the bat file above? 我应该在上面的bat文件中添加什么命令?

use: 采用:

 start "" myapplication.exe > mytextfile.txt 2>&1

instead you could run batch file from cmd to know what is the error 相反,你可以从cmd运行批处理文件,以了解错误是什么

Try this, to see the error message: 试试这个,看看错误信息:

cd /d "%~dp0my_subfolder"
start "" /b myapplication.exe
pause

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM