Reputation: 4692
I am able to successfully pass arguments into a console application using the following:
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = Properties.Settings.Default.EmailBlasterAppPath;
string subject = txtSubject.Text.Replace(@"""", @"""""");
string emailbody = txtEmail.Text.Replace(@"""", @"""""");
string args = String.Format("{0},{1},{2},{3},{4}",
"SendPlainEmail",
B2BSession.Doctor.DoctorId.ToString(),
DocEmail.Trim(), subject, emailbody);
psi.Arguments = args;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
Process process = Process.Start(psi);
However, once inside the console application, the console app only expects parameters as single strings separated by a space (see below):
static void Main(string[] args)
My problem is that I'm passing a subject line and email body into the console application, but it only picks up the first word in the parameter. So, if I pass in something like this (note that "test subject line" should be one argument and "test body line" would be another argument) for a total of 5 arguments:
SendPlainEmail 25498 [email protected] test subject line test body line
but, the console app would parse it as having 9 arguments (one for each word):
SendPlainEmail 25498 [email protected] test subject line test body line
Is there a way to pass the parms into the console app with just the 5 arguments where the subject and body are treated as a single argument?
So, as you can see, right before the Process.Start statement, what is contained in the psi.arguments property.
The data is being passed correctly, it's just that the receiving console application can only receive an array of strings separated by a space. So, instead of the 4th and 5th arguments being "test subject line" and "test body line" respectively, the console app process it as the following:
args[3] = test
args[4] = subject
args[5] = line
args[6] = test
args[7] = body
args[8] = line
So, in lieu of this, how can I treat "test subject line" and "test body line" as one item in the array respectively?
Upvotes: 0
Views: 10763
Reputation: 12348
You need to surround the parameters in quotes ( "
), so it's like
SendPlainEmail 25498 [email protected] "test subject line" "test body line"
else it wouldn't know where your subject ends and your body begins. ;)
Upvotes: 2