我尝试使用带有vb .net的gnokii sms库(http://gnokii.org/)发送短信,im创建了一个单独的bat文件,并从我的vb.net代码中调用了该bat文件
这是我的VB代码
Dim process As New System.Diagnostics.Process
Dim startInfo As New ProcessStartInfo(AppDomain.CurrentDomain.BaseDirectory & "sms.bat")
process.StartInfo = startInfo
process.StartInfo.Arguments = txtBody.Text'text typed in text box
这是我的蝙蝠文件
@echo off
echo Begin Transaction
echo "message body" | c:\sms\gnokii.exe --sendsms 0771234567 'this is mobile no
pause
我的问题是我想将两个参数传递给消息正文和移动,而没有硬编码
消息主体由空格和多行组成,并且移动没有共处,只有一行没有空格
我如何在bat文件中实现
请帮忙
首先,您应该测试是否gnokii.exe
通过管道接受多行文本。
只需创建一个多行文本文件并尝试使用
type mySMS.txt | c:\sms\gnokii.exe --sendsms 0771234567
如果可行,则还可以从批处理文件中发送它,并在文本中添加换行符。
@echo off
setlocal EnableDelayedExpansion
set LF=^
rem ** The two empty lines are required **
echo Begin Transaction
echo Line1!LF!Line2 | c:\sms\gnokii.exe --sendsms 0771234567 'this is mobile no
使用换行符时,应使用EnableDelayedExpansion。
也存在将其与百分比扩展一起使用的解决方案,但这要复杂得多。
解释dos-batch换行符变量hack的工作方式
要将其与注释中的参数一起使用,您需要在VB中格式化消息。
因此,当您想要发送类似
您好,
这是
三行文字
您需要发送到批次
process.StartInfo.Arguments = "Hello!LF!this is a text!LF!with three lines"
您的批次应该看起来像
setlocal EnableDelayedExpansion
set LF=^
set "text=%~1"
echo !text! | c:\sms\gnokii.exe --sendsms %2
第二种解决方案,当它不起作用时。
创建一个临时文件并使用重定向
setlocal EnableDelayedExpansion
set LF=^
set "text=%~1"
echo !text! > "%TMP%\sms.txt"
c:\sms\gnokii.exe --sendsms %2 < "%TMP%\sms.txt"
del "%TMP%\sms.txt"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句