是否可以在脚本内重定向批处理文件的输出? [英] Is it possible to redirect the output of a batch file inside the script?

查看:20
本文介绍了是否可以在脚本内重定向批处理文件的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将批处理脚本的标准输出设置为转到文件.如果可能,我想在脚本中执行此操作.

I would like to set the standard output of a batch script to go to a file. I would like to do this inside the script if possible.

注意:不想这样做:foo.bat >标准输出.txt

我想在脚本中做一些事情来将输出重定向到一个文件
例如:

I would like to do something inside the script to redirect the output to a file
For example:

foo.bat

:: Redirect standard output to StdOut.txt
:: Insert batch code to do what I want here.

推荐答案

一种方法如下.使用 call 命令执行脚本中的标签.编辑 我意识到我发布的第一个版本似乎在 cmd.exe 提示符下不起作用(我使用的是 TCC).以下似乎适用于两个命令处理器:

One way of doing it is the following. Use the call command to execute a label in the script. Edit I realized the first version I posted does not seem to work in a cmd.exe prompt (I was using TCC). The following seems to work in both command processors:

@echo off
call :testitout > t.tmp
goto:eof

:testitout
echo Hi There
echo Goodbye

这篇关于是否可以在脚本内重定向批处理文件的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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