[英]showing output from a called batch file on command prompt window?
I have 2 batch files (say a.bat and b.bat). 我有2个批处理文件(例如a.bat和b.bat)。 I am calling b.bat from a.bat:
@call b.bat
我正在从a.bat呼叫b.bat:
@call b.bat
There are some echo statements in b.bat, some DB start commands which usually show messages like starting DB service...service started .. some copy file statements... b.bat中有一些echo语句,一些DB启动命令通常会显示诸如启动DB服务的消息...服务已启动 ..一些复制文件语句...
I am putting all these messages form b.bat into a log file. 我将所有这些消息形式从b.bat放入日志文件。 for example:
sc delete ServName >> C:\\test\\log.log
.. These service delete messages are going into the log files successfully 例如:
sc delete ServName >> C:\\test\\log.log
..这些服务删除消息已成功进入日志文件
When I run the b.bat directly, it shows me all these messages on the command prompt and the log file, however when i call b.bat from a.bat, these (copy file, start db etc etc) messages are not shown on the command prompt.. they only show up in the log file.... 当我直接运行b.bat时,它将在命令提示符和日志文件中显示所有这些消息,但是当我从a.bat调用b.bat时,这些(复制文件,启动db等)消息不会显示在命令提示符下..它们仅显示在日志文件中。
Is there a way to show all these return messages form b.bat file on the cmd window when its called by a.bat?? 当由a.bat调用时,有没有办法在cmd窗口上显示所有来自b.bat文件的返回消息?
Thanks 谢谢
If you just want to see the result after execution, just add a "TYPE logfile.log" to the end. 如果只想在执行后查看结果,则在末尾添加“ TYPE logfile.log”。
Cmd doesn't support multiple output streams or replication, so if you want a "live view" one needs to process the line's one by one from the pipe: Cmd不支持多个输出流或复制,因此,如果要“实时视图”,则需要从管道中逐行处理该行:
for /f "tokens=*" %f in ('Call b.bat') do @echo %f && @echo %f >>log.txt
/ f“ tokens = *”%f in('Call b.bat')执行@echo%f && @echo%f >> log.txt
If you are doing this from a.bat, you might need to replace %f to %%f 如果您是通过a.bat执行此操作,则可能需要将%f替换为%% f
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.