Runtime Error

The command to send SMS text messages from GAMMU is

gammu --sendsms ems 144 -text Hello

wiith 144 a sample number.

I, therefore, use the code

Runtime.getRuntime().exec("gammu --sendsms ems 144 -text Hello");

to send an sms text message from Java.

Now, supposing the text contains more than one word. In GAMMU i can do

gammu --sendsms ems 144 -text"Hello World"

or

gammu --sendsms ems 144 -text Hello\ World

which in Java code I may do

Runtime.getRuntime().exec("gammu --sendsms ems 144 -text \"Hello World\"");

or

Runtime.getRuntime().exec("gammu --sendsms ems 144 -text Hello\ World");

to perform the operation. I have the number read from a database and the message too. Here is a sample code

String number = resultSet.getString("number");

String message = resultSet.getString("messageToSend");

String command ="gammu --sendsms ems " + number +" -text \"" + message +"\"";

Runtime.getRuntime().exec(command);

This code is not working because the sample command below

gammu --sendsms ems 144 -text Hello World

returns an error message

Unknown parameter"World"

because of the space between hello and world. This error is also present in Runtime despite my specifying the message in double quotes. Could anyone help me out here?

Thanks.

[1644 byte] By [Jamwaa] at [2007-11-27 10:40:02]
# 1

Runtime.exec(String) is a convenience method that splits the given command around spaces to produce paramters, then call exec(String[]).

In order to have better control over the parameters, you should therefore build your array yourself and call exec(String[]).

Something like :String number = resultSet.getString("number");

String message = resultSet.getString("messageToSend");

String[] command = {"gammu", "--sendsms", "ems", number, "-text", message};

Runtime.getRuntime().exec(command);

TimTheEnchantora at 2007-7-28 19:04:32 > top of Java-index,Java Essentials,Java Programming...
# 2

Thanks, TimTheEnchantor

Jamwaa at 2007-7-28 19:04:32 > top of Java-index,Java Essentials,Java Programming...