我试图使用gnokii短消息库(http://gnokii.org/)与vb.net一起发送短消息,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我的问题是,如果没有硬代码,我想将两个参数传递给消息体和mobile。
消息体由空格和多行组成,移动不共接,只有单行没有空格。
如何在bat文件中实现?
请帮帮忙
发布于 2013-12-17 08:37:45
首先,您应该测试,如果gnokii.exe通过管道接受多行文本。
只需创建一个多行文本文件并使用
type mySMS.txt | c:\sms\gnokii.exe --sendsms 0771234567如果这样做有效,也应该可以从批处理文件发送它,并将linefeed添加到文本中。
@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。
也有解决方案来使用它的百分之扩展,但这要复杂得多。
Explain how dos-batch newline variable hack works
要将它与注释中的参数一起使用,您需要在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"https://stackoverflow.com/questions/20628585
复制相似问题