如何使用Windows中的批处理文件记录并行进程 [英] How do I log parallel process using batch file in windows

查看:152
本文介绍了如何使用Windows中的批处理文件记录并行进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行两个并行进程的批处理文件。我们想将这两个进程记录到两个单独的文本文件中。

使用bat文件调用进程,同样是使用这个bat文件获取日志。



但是这个过程只创建日志文件但没有记录任何文件。

如果您有任何解决方案,请告诉我,我已经提供了相似的代码供您参考。 />


批处理文件参考代码: -



启动ping Testdb1> C:\ Users\log \Test1.txt 
start ping Testdb2> C:\ Users\log\Test2.txt





我尝试了什么:



当我们按顺序进行记录时,以及当我将蝙蝠文件分成单独的文件然后尝试从主文件中调用它然后它也在工作时记录它。

任何帮助都是appriciated

解决方案

这些命令会将 start 命令的输出重定向到文本文件。而ping启动一个没有重定向的新进程。您应该创建一个执行ping并重定向输出的新批处理文件。类似于:

 // myping.bat 
ping%1> %2


替代(但不推荐)的方法是:

 start cmd.exe / C ^(ping Testdb1 ^> C:\ Users\log\Test1.txt ^)
start cmd.exe / C ^(ping Testdb2 ^> C:\ Users\log \ Test2.txt ^)



在此处找到:批处理文件 - 如何... 。显示和重定向输出 [ ^ ]


I am having a batch file which runs two parallel processes. We want to log these two processes into two separate text files.
Process is getting called using bat file and same is getting log using this bat file.

But this process only creating the log files but not logging anything into the files.
Please let me know if you have any solution, I have given the similar code for your reference.

batch file reference code:-

start ping Testdb1> C:\Users\log\Test1.txt
start ping Testdb2 > C:\Users\log\Test2.txt



What I have tried:

It's logging when we are making it sequential and also when i split the bat files into separate files and then try calling it from master one then also it's working.
Any help would be appriciated

解决方案

Those commands will redirect the output of the start command to the text file. while the ping starts a new process with no redirection. You should create a new batch file that performs the ping and redirects the output. Something like:

// myping.bat
ping %1 > %2


The alternative (but not recommended) approach would be:

start cmd.exe /C ^(ping Testdb1 ^> C:\Users\log\Test1.txt^)
start cmd.exe /C ^(ping Testdb2 ^> C:\Users\log\Test2.txt^)


Found here: Batch files - How To ... Display and Redirect Output[^]


这篇关于如何使用Windows中的批处理文件记录并行进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆