Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

Note: I do not want to do this: foo.bat > StdOut.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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
854 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...