每個人
bat 函式如何重定向到檔案?
例子:
:func
call run-server.bat %* 2>&1 >>./server.log
goto:eof
call :func %* 2>&1 >>./run.log
uj5u.com熱心網友回復:
在 Windows 中(就像在 UNIX/Linux 中一樣),您可以使用以下>字符重定向到輸出檔案:
> : write to file (recreate a new file if needed)
>> : append to file (create the file if it does not exist yet)
例子:
echo tralala >writetofile.txt
echo tralala >writetofile.txt
echo tralala >>appendtofile.txt
echo tralala >>appendtofile.txt
檔案“writetofile.txt”:
tralala
檔案“appendtofile.txt”:
tralala
tralala
運算式2>&1用于在 Linux 和 UNIX 環境中將錯誤輸出重定向到標準輸出,但在 Windows 中不使用。
uj5u.com熱心網友回復:
@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
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/410154.html
標籤:
下一篇:從哈希Ruby列印指定值
