Home > Net >  How to bat function redirects to a file?
How to bat function redirects to a file?

Time:01-12

Everyone

How do bat functions redirect to a file?

Example:

:func
call run-server.bat %* 2>&1 >>./server.log
goto:eof
call :func %* 2>&1 >>./run.log

CodePudding user response:

@echo off set "var=a string with a caret^ and an > arrow"

call :SomeFunc var exit /b

:SomeFunc setlocal EnableDelayedExpansion set "param1=!%1!" echo !param1! exit /b

CodePudding user response:

In Windows (just like in UNIX/Linux) you can redirect to an output file using the > character:

>  : write to file (recreate a new file if needed)
>> : append to file (create the file if it does not exist yet)

Examples:

echo tralala >writetofile.txt
echo tralala >writetofile.txt

echo tralala >>appendtofile.txt
echo tralala >>appendtofile.txt

file "writetofile.txt":

tralala

file "appendtofile.txt":

tralala
tralala

The expression 2>&1, which is used for redirecting error output to the standard output in Linux and UNIX environments, is not used in Windows.

  •  Tags:  
  • Related