从批处理文件中重定向输出 [英] Redirecting Output from within Batch file
问题描述
我创建一些简单的命令的批处理文件从系统收集信息,批处理文件中包含的命令来获取时间,IP信息,用户....等我组装在一个批处理文件中的所有命令,它运行,但我想批处理文件,运行时输出结果到一个文本文件(日志),是没有办法,我可以添加到批处理,会做这样的命令。请记住,我不希望运行CMD批处理,然后重定向输出,我想输出从批次内的重定向,如果这是可能的。
I am Creating a batch file with some simple commands to gather information from a system, the batch file contains commands to get the time, IP information, users....etc.. I assembled all the commands in a batch file, and it runs, but I would like the batch file, when run to output the results to a text file (log), is there a command that I can add to the batch that would do so. Keep in mind I do not want to run the batch from cmd, then redirect output, I want to redirect the output from inside the batch, if that is possible.
推荐答案
简单幼稚的方法(低效率)
The simple naive way (less efficient)
@echo off
command1 >output.txt
command2 >>output.txt
...
commandN >>output.txt
有一个更好的方式 - 更容易编写和更快
A better way - easier to write, and faster.
@echo off
>output.txt (
command1
command2
...
commandN
)
另一个好办法
@echo off
call :sub >output.txt
exit /b
:sub
command1
command2
...
commandN
这篇关于从批处理文件中重定向输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!