[英]How to bat function redirects to a file?
Everyone每个人
How do bat functions redirect to a file? bat 函数如何重定向到文件?
Example:例子:
:func
call run-server.bat %* 2>&1 >>./server.log
goto:eof
call :func %* 2>&1 >>./run.log
@echo off set "var=a string with a caret^ and an > arrow" @echo off set "var=a string with a caret^ and an > arrow"
call:SomeFunc var exit /b调用:SomeFunc var exit /b
:SomeFunc setlocal EnableDelayedExpansion set "param1=!%1!" :SomeFunc setlocal EnableDelayedExpansion set "param1=!%1!" echo !param1!回声!参数1! exit /b退出 /b
In Windows (just like in UNIX/Linux) you can redirect to an output file using the >
character:在 Windows(就像在 UNIX/Linux 中一样)中,您可以使用>
字符重定向到 output 文件:
> : 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":文件“writetofile.txt”:
tralala
file "appendtofile.txt":文件“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. 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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.