首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >批处理文件中的if else语句格式

问批处理文件中的if else语句格式
EN

Stack Overflow用户
提问于 2017-04-26 12:13:45
回答 4查看 734关注 0票数 0

我是批处理脚本的新手,正在尝试执行以下if语句,命令提示符返回有关语法的错误。我在互联网上到处搜索,似乎无法得到如何在批处理文件中执行if else语句的直接答案。格式化此语句的正确方式是什么?任何帮助都将不胜感激。

代码语言:javascript
复制
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 )
                    )
EN

回答 4

Stack Overflow用户

发布于 2017-04-26 14:07:16

这可能不是最好的代码,但这或多或少是如何实现的。

代码语言:javascript
复制
@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来测试它,以查看不同的结果。

票数 1
EN

Stack Overflow用户

发布于 2017-04-26 12:41:52

代码语言:javascript
复制
if "string1" operator "string2" (dothis) else (dothat)

重要的空间。) else (必须在一行上。

代码语言:javascript
复制
if "string1" operator "string2" (
 dothis
 then dothis
 after that dothis
) else (
 dothat
 then dothat
 after that dosomethingelse
)
票数 0
EN

Stack Overflow用户

发布于 2017-04-26 17:37:26

我会减少冗余,使用更好的缩进:

代码语言:javascript
复制
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应该做什么。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43624918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档