本文介绍了获取标准输出到一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
即时通讯使用在一个批处理文件。在发送邮件的末尾它succses或失败的消息回信。例如:
Im using sendemail in a batch file. At the end of sending an email it replys with a message of succses or failure. For example
Jan 10 00:46:54 villa sendemail[456]: Email was sent successfully!
是否有可能捕捉到这个信息转化为加工变量?
Is it possible to capture this message into a variable for processing?
THX
推荐答案
是的,你需要通过循环来执行sendmail的:
Yes, you need to execute sendmail through the for loop:
for /f "tokens=*" %%a in ('[sendmail command line]') do (
set VAR=%%a
)
这运行后,VAR将被设置为sendmail的输出的最后一行。然后,您可以做这一行的处理
After this runs, VAR will be set to the last line that sendmail output. You can then do processing on that line
for /f "tokens=5,* delims= " %%a in (%VAR%) do (
if "%%b"=="Email was sent successfully!" (
echo SUCCESS
exit /b 0
) else (
echo FAILURE
exit /b 1
)
)
这篇关于获取标准输出到一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!