将多个bat文件的输出重定向到一个控制台窗口

时间:2019-07-24 04:25:30

标签: windows powershell batch-file cmd

出于开发目的,我正在本地运行多个微服务。目前,我是通过.bat脚本来执行此操作的,我在其中调用其他正在启动服务的.bat文件。它会启动多个控制台窗口,这在输出之间导航并不方便。

正在启动服务的脚本如下所示:

start cmd /k call api_one.bat
start cmd /k call api_two.bat
...

在api_xxx.bat中,我将使用api启动iisexpress。

我正在寻找一种使它更舒适的方法。例如,通过将所有输出重定向到单个输出,并带有例如前缀来标识来自哪些脚本输出行。

2 个答案:

答案 0 :(得分:2)

我遇到了类似的问题,我从一个批处理文件中调用了一个批处理文件,而该批处理文件又启动了另一个批处理文件。

test.bat的内容:

set logname=.\log.log

if exist %logname% ( type nul > %logname% 
)

echo Now starting example.bat>>%logname%

call C:\example.bat >>%logname%

echo finished example.bat>>%logname%

所以现在这是example.bat的内容:

echo starting integrated commands

start /b cmd /k "C:\example2.bat"

[some code to check for a process that starts in example2.bat] 

echo finished integrated commands

,example2.bat的内容可以是您想要的任何内容,也可以显示在日志文件中。

请注意,我的example2.bat在结尾处有一个出口,因为example.bat会检查example2.bat是否正在运行。仅在完成时才继续执行脚本。就我自己而言,我将所有3个脚本的所有内容都整合到一个日志文件中。

答案 1 :(得分:0)

尝试:

cmd /c ""call api_one.bat" " >>output.txt
cmd /c ""call api_two.bat" " >>output.txt
::Etc ...
相关问题