简体   繁体   English

在命令提示符窗口中显示被调用批处理文件的输出?

[英]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.

相关问题 批处理文件执行后关闭命令提示符窗口 - Close command prompt window after batch file execution 如何使 Java 在同一命令提示符窗口中打开批处理文件 - How to Make Java Open a Batch File in Same Command Prompt Window 从Windows命令提示符/批处理文件中的路径字符串获取叶 - Getting the leaf from a path string in Windows Command Prompt/batch file 从批处理文件启动.exe时,奇怪的命令提示符挂起 - Weird Command Prompt hang when starting .exe from a batch file 是否可以从批处理文件(命令提示符)中使用uglifyjs? 如果是这样,怎么办? - Is it possible to use uglifyjs from a batch file (command prompt)? If so, how? 编写批处理文件与在提示符下编写命令有何不同? - writing batch file is different from writing command in the prompt? 从批处理文件启动的命令提示符在操作停止时关闭 - Command prompt started from batch file closes when operation is stopped 从批处理文件中的新命令提示符中终止进程 - Killing a process from a new command prompt in a batch file 命令提示符显示“mongorestore”不是内部或外部命令,也不是可运行的程序或批处理文件 - command prompt are showing 'mongorestore' is not recognized as an internal or external command, operable program or batch file 命令在命令提示符中有效,但在批处理文件中无效 - Command works in Command Prompt but not in a batch file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM