简体   繁体   English

是否可以在批处理脚本中同时显示和重定向标准输出?

[英]Is it possible to display and redirect standard output in the same time in Batch script?

I am trying to do我正在尝试做

  call script.bat > script.log

But it does not display result in the console.但它不会在控制台中显示结果。 So currently I have to do所以目前我必须做

 call script.bat
 call script.bat > script.log

which is really inefficient.这真的是低效的。

Is there a way to both display output to the console and output it to log file?有没有办法将输出显示到控制台并将其输出到日志文件? I know one of the option is我知道其中一种选择是

call script.bat > script.log
type script.log

But that doesn't really work if script.bat is only one of the step in a long batch process, I would like to see the output for each step as it is being called instead of one execution of type at the end of all of the calls.但是,如果 script.bat 只是一个长批处理过程中的一个步骤,那这真的不起作用,我希望看到每个步骤的输出,因为它被调用而不是在所有的结束时执行一次类型电话。

If you work with the windows Power-Shell (as i assume of the windows tag) there is a cmdlet called Tee-Object.如果您使用 windows Power-Shell(正如我假设的 windows 标记),则有一个名为 Tee-Object 的 cmdlet。

help Tee-Object

NAME
    Tee-Object

SYNOPSIS
    Saves command output in a file or variable and displays it in the console.

Under Unix there is the programm tee that provides the same functionality.在 Unix 下有提供相同功能的程序tee

You can't.你不能。

Option 1:选项1:

call "script.bat" > "script.log" | type "script.log"

Option 2:选项 2:

wintee http://code.google.com/p/wintee/ wintee http://code.google.com/p/wintee/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM