带参数启动gammu

Start gammu with parameters

我想用gammu发送带有地址和信息的短信,但是gammu参数有问题。如果我只启动它运行的程序 (string cmd1 = "c:\G133\bin\gammu.exe ";)。添加参数后出现此故障:

System.ComponentModel.Win32Exception' occurred in System.dll
Additional information: The system cannot find the file specified:

代码:

string[] sms = File.ReadAllLines(@"C:\temp\test.txt");

string address = sms[0];
string message = sms[1];

string cmd1 = @"C:\G133\bin\gammu.exe --sendsms TEXT" + " " +  
    "\"" + address + "\" -text " + " " + "\"" + message + "\"";

System.Diagnostics.Process.Start(cmd1);

谁能帮帮我?提前致谢。

输出看起来不错:

Console.WriteLine(cmd1); - result

C:\G133\bin\gammu.exe --sendsms TEXT +12121234567 -text "Hello"

您应该拆分应用程序和参数:

Process.Start(@"C:\G133\bin\gammu.exe", "--sendsms TEXT +12121234567 -text \"Hello\"");

您需要调用带有两个参数的Start方法的重载:

  • 第一个:文件到运行;
  • 第二个:参数

它看起来像:

string app = @"path\to\your\target\app";
string prms = "your parameters";

System.Diagnostics.Process.Start(app, prms);