StartInfo arguments with embedded space

  • Thread starter Thread starter walter1234
  • Start date Start date
W

walter1234

I have this code which runs a Crystal Report and passes a parameter
"hello_world"
Works fine. if I remove the underscore char and pass "hello world", it fails

FileInfo logicityPath = new FileInfo(@"C:\Program
Files\SaberLogic\Logicity\Logicity Desktop.exe");
string logicity_Path = logicityPath.FullName;
FileInfo RRDPath = new
FileInfo(@"F:\Payroll\PayrollReports\ExportedReports\LineItemReport.rrd");
string rrdPath = RRDPath.FullName;
ProcessStartInfo startInfo = new ProcessStartInfo();
Process pStart = new Process();
string arguments = rrdPath + " " + "rptTxt=hello_world";
startInfo = new ProcessStartInfo(logicity_Path, arguments);
pStart.StartInfo = startInfo;
pStart.Start();

It seems that I should use string.format to build the argument, but I can't
figure out how to pas a string with an embedded space
Can someone help?
Can you point me to some documentation about how to use the excape
characters in the string.format method.

args = string.Format("{0}\"\"{1}\"", rrdPath, p1);
if I change anything, I get the red squigglies
Thanks for any help
 
[...]
Can you point me to some documentation about how to use the excape
characters in the string.format method.

args = string.Format("{0}\"\"{1}\"", rrdPath, p1);
if I change anything, I get the red squigglies

If you change _anything_? That's not true.

As for your actual question, you don't need the String.Format() method.
You're not doing anything that you can't do with regular concatenation.
It seems like the real problem is failing to understand your executable's
command line argument requirements (that is, the arguments for "Logicity
Desktop.exe", whatever that is).

Surely the text "hello world" has to be quoted in order for the entire
string to be used as the value for "rptText". So, put double quotes
around it.

Here's a document page explaining everything a beginner would want to know
about strings in C#:
http://msdn.microsoft.com/en-us/library/ms228362.aspx

Note also that there's no point in all that code that uses FileInfo. Just
assign the path as a text string. And since you're just going to create a
whole new ProcessStartInfo() instance, there's no point in creating one
where you declare the "startInfo" variable. Better yet, don't even
declare the variable until after you've created the strings you're going
to pass to the constructor. Then you can declare and initialize it at the
same time.

Pete
 
I actually just got it to work using FileInfo. the command line that finally
worked was:

"F:\\Payroll\\PayrollReports\\ExportedReports\\LineItemReport.rrd
rptTxt=\"hello world\""

if i remove the escape chars around the text, it doesn't work. Crystal
prompts me for the parameter value
Anyway, I will read the article I'm sure there is much I don't know about
..NET strings.
Thanks for your help


Peter Duniho said:
[...]
Can you point me to some documentation about how to use the excape
characters in the string.format method.

args = string.Format("{0}\"\"{1}\"", rrdPath, p1);
if I change anything, I get the red squigglies

If you change _anything_? That's not true.

As for your actual question, you don't need the String.Format() method.
You're not doing anything that you can't do with regular concatenation.
It seems like the real problem is failing to understand your executable's
command line argument requirements (that is, the arguments for "Logicity
Desktop.exe", whatever that is).

Surely the text "hello world" has to be quoted in order for the entire
string to be used as the value for "rptText". So, put double quotes
around it.

Here's a document page explaining everything a beginner would want to know
about strings in C#:
http://msdn.microsoft.com/en-us/library/ms228362.aspx

Note also that there's no point in all that code that uses FileInfo. Just
assign the path as a text string. And since you're just going to create a
whole new ProcessStartInfo() instance, there's no point in creating one
where you declare the "startInfo" variable. Better yet, don't even
declare the variable until after you've created the strings you're going
to pass to the constructor. Then you can declare and initialize it at the
same time.

Pete
 
Back
Top