2

im try to send sms using gnokii sms library (http://gnokii.org/) with vb .net,im created a seperate bat file and call that bat file from my vb.net code

this is my vb code

 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

this is my bat file

@echo off
echo Begin Transaction
echo "message body" |  c:\sms\gnokii.exe   --sendsms 0771234567 'this is mobile no
pause

my problem is i want to pass two parameters to message body and mobile no without hard code them

message body consisted with spaces and multilines and mobile no cosistend only single line without spaces

how can i Achieve in bat file

please help

Amila Thennakoon
  • 390
  • 1
  • 4
  • 14

1 Answers1

2

First you should test, if the gnokii.exe accepts multiline texts via a pipe.
Simply create a multiline text file and try it with

type mySMS.txt | c:\sms\gnokii.exe   --sendsms 0771234567

If this works it should be also possible to send it from a batch file and add linefeeds into the text.

@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 should be used when linefeed characters are used.
There exists also solutions to use it with percent expansion, but that is much more complicated.
Explain how dos-batch newline variable hack works

To use this with parameters like in your comment, you need to format the message in VB.

So when you want to send a text like

Hello
this is a text
with three lines

You need to send to the batch

process.StartInfo.Arguments = "Hello!LF!this is a text!LF!with three lines"

And your batch should look like

setlocal EnableDelayedExpansion
set LF=^


set "text=%~1"
echo !text! | c:\sms\gnokii.exe --sendsms %2

A second solution, when this doesn't work.

Create a temporary file and use redirection

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"
Community
  • 1
  • 1
jeb
  • 70,992
  • 15
  • 159
  • 202
  • what is line 1 and line 2 ,from vb.net ill pass morethan 2 line how to do it ? – Amila Thennakoon Dec 17 '13 at 08:52
  • Nice jeb! Can you explain why EnableDelayedExpansion is required for this to work? – RGuggisberg Dec 17 '13 at 10:14
  • @AmilaThennakoon `line1` and `line2` is the multiline text for your SMS. When you want to pass more than two lines add more linefeeds like `Hello!LF!this is line2!LF!this is line3` – jeb Dec 17 '13 at 11:14
  • @RGuggisberg I added an explanation and link – jeb Dec 17 '13 at 11:14
  • echo %1 | c:\sms\gnokii.exe --sendsms %2 this is my bat file %1 should have spaces and multiline %2 has only sigle line how can im get seperate them when im sending parameters – Amila Thennakoon Dec 17 '13 at 11:18
  • @jeb Dear mr.jeb thank a lot to your attention and for your valuable time im tried as you said but when receive the sms its only has Hello , im tried wit several messages but its same as it is – Amila Thennakoon Dec 17 '13 at 17:06
  • @AmilaThennakoon Does it works with `type mySMS.txt | c:\sms\gnokii.exe ...` ? – jeb Dec 17 '13 at 18:53
  • @jeb Dear Mr jeb im tried to send sms use text file as this gnokii.exe --sendsms +48501123456 < "C:\path_to_textfile\file.txt" that text file contains multilevel lines and spaces .... im recived sms as it is correctly ... – Amila Thennakoon Dec 18 '13 at 03:18
  • @AmilaThennakoon `gnokii.exe --sendsms +491234 < file.txt` is redirection and it can work different to pipes – jeb Dec 18 '13 at 07:35
  • @jeb Dear MR.Jeb you helped me a lot .... but i think i couldn't achive my objectives using gnokii thank you alot for helping – Amila Thennakoon Dec 18 '13 at 07:57