0

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?

1
  • 2
    Arguments must be separated by a space or a tab. Replace the commas in the format string with a space. Commented Apr 28, 2012 at 16:55

1 Answer 1

2

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. ;)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.