--- tags: batch --- # 如何解決`The filename, directory name, or volume label syntax is incorrect.`錯誤訊息 ## 狀況 我的批次檔如下,執行後都會出錯 ```batch= @echo off chcp 65001 set "log=..\storage\script\vsms-000.log" echo 更新每季定期掃描的排程與資產狀況 >> "%log%" 2>&1 ``` 執行後會出現以下錯誤訊息 `The filename, directory name, or volume label syntax is incorrect.` ## 原因 批次檔案中有特殊字符,特別是在中文或其他非ASCII字符的情況下,可能會遇到問題 我批次檔是使用utf8儲存的,不想使用ANSI儲存,所以開始摸索解法 ## 嘗試了以下不同的寫法都還是會出錯 `echo 更新每季定期掃描的排程與資產狀況 >> "%log%" 2>&1` => '排程與資產狀況' is not recognized as an internal or external command, operable program or batch file. `echo "更新每季定期掃描的排程與資產狀況" >> "%log%" 2>&1` => The filename, directory name, or volume label syntax is incorrect. `(echo 更新每季定期掃描的排程與資產狀況) >> "%log%" 2>&1` => '�排程與資產狀況)' is not recognized as an internal or external command, operable program or batch file. ## 最後解決方法如下 一定要換行~~ ```batch= ( echo 更新每季定期掃描的排程與資產狀況 ) >> "%log%" 2>&1 ``` 感謝大家
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up