我是批处理脚本的新手,正在尝试执行以下if语句,命令提示符返回有关语法的错误。我在互联网上到处搜索,似乎无法得到如何在批处理文件中执行if else语句的直接答案。格式化此语句的正确方式是什么?任何帮助都将不胜感激。
if !cnt! geq 20 (
if !size! lss 5000000(sent>%cd%\EmailSent.txt
mailsend1.19.exe -to !email! -from test@gmail.com -ssl -smtp smtp.gmail.com -port 465 -sub "test" -M "The capture quality is not sufficient. Please retake capture." -auth-plain -user "test@gmail.com" -pass) else(sent>%cd%\EmailSent.txt
mailsend1.19.exe -to !email! -from test@gmail.com -ssl -smtp smtp.gmail.com -port 465 -sub "test" -M "The capture quality is ok. Patient good to go." -auth-plain -user "test@gmail.com" -pass )
)发布于 2017-04-26 14:07:16
这可能不是最好的代码,但这或多或少是如何实现的。
@echo off
IF %this%==not_this (
echo no match
) ELSE IF %this%==this (
echo matches
) ELSE (
echo Did not find match
)您可以在运行脚本之前执行set this=this、set this=not_this或set this=something_else来测试它,以查看不同的结果。
发布于 2017-04-26 12:41:52
if "string1" operator "string2" (dothis) else (dothat)重要的空间。) else (必须在一行上。
if "string1" operator "string2" (
dothis
then dothis
after that dothis
) else (
dothat
then dothat
after that dosomethingelse
)发布于 2017-04-26 17:37:26
我会减少冗余,使用更好的缩进:
Set MailArgs=-to !email! -from test@gmail.com -ssl -smtp smtp.gmail.com -port 465 -sub "test" -auth-plain -user "test@gmail.com" -pass
if !cnt! geq 20 (
if !size! lss 5000000 (
sent>%cd%\EmailSent.txt
mailsend1.19.exe %MailArgs% -M "The capture quality is not sufficient. Please retake capture."
) else (
sent>%cd%\EmailSent.txt
mailsend1.19.exe %MailArgs% -M "The capture quality is ok. Patient good to go."
)
)我不清楚sent>%cd%\EmailSent.txt应该做什么。
https://stackoverflow.com/questions/43624918
复制相似问题