简体   繁体   English

命令在命令提示符下工作,但不在批处理文件中

[英]command work in command prompt but not in batch file

I am trying to send out email attachment periodically from a batch script using this command line client 我正在尝试使用此命令行客户端定期从批处理脚本发送电子邮件附件

http://caspian.dotconf.net/menu/Software/SendEmail http://caspian.dotconf.net/menu/Software/SendEmail

the command for it is pretty straightforward 该命令非常简单

sendEmail -t abc@gmail.com -u hellp -f abd@nus.edu.sg -m world -s smtp.nus.edu.sg -xu nusstu\a123456 -xp helloworld! -a C:\Users\ll\Desktop\Quotes.docx

The strange thing is if I type that line in command prompt, it works perfectly fine. 奇怪的是,如果我在命令提示符下键入该行,则效果很好。 I can receive the email with attachment. 我可以收到带有附件的电子邮件。

However, when I put it into a batch script, like 但是,当我将其放入批处理脚本时,例如

:email
sendEmail -t abc@gmail.com -u hellp -f abd@nus.edu.sg -m world -s smtp.nus.edu.sg -xu       nusstu\a123456 -xp helloworld! -a C:\Users\ll\Desktop\Quotes.docx
goto:eof

and I call this subroutine in my batch file, the output says 然后在批处理文件中调用此子例程,输出显示

SMTP:AUTH authentication to smtp.nus.edu.sg:25 failed.

I checked. 我检查了。 no typo, Could someone help me what is the difference? 没有错字,有人可以帮我有什么区别吗? why the same command works in command line but cause trouble in a script file? 为什么同一命令在命令行中有效,但在脚本文件中引起麻烦?

Thanks 谢谢

I believe you're censoring your batch too much. 我相信您对您的批次检查过多。

Try running the following: 尝试运行以下命令:

@ECHO OFF

setlocal
echo sendEmail -t abc@gmail.com -u hellp -f abd@nus.edu.sg -m world -s smtp.nus.edu.sg -xu nusstu\a123456 -xp helloworld! -a C:\Users\ll\Desktop\Quotes.docx
endlocal

SETLOCAL enabledelayedexpansion
echo sendEmail -t abc@gmail.com -u hellp -f abd@nus.edu.sg -m world -s smtp.nus.edu.sg -xu nusstu\a123456 -xp helloworld! -a C:\Users\ll\Desktop\Quotes.docx
echo sendEmail -t abc@gmail.com -u hellp -f abd@nus.edu.sg -m world -s smtp.nus.edu.sg -xu  nusstu\a123456 -xp helloworld^^! -a C:\Users\ll\Desktop\Quotes.docx
goto:eof

Because your password contains ! 因为您的密码包含! , batch interprets that as a variable-name if DELAYEDEXPANSION is invoked. ,如果调用DELAYEDEXPANSION,则批处理将其解释为变量名。 Since the variablename isn't set, it's replaced by [nothing] and sendtoemail believes that your password is helloworld\\Users\\ll\\Desktop\\Quotes.docx - hence the error message. 由于未设置变量名,因此将其替换为[nothing],并且sendtoemail认为您的密码为helloworld\\Users\\ll\\Desktop\\Quotes.docx因此出现错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM