Passing an option to an EXE from an EXE

  • Thread starter Thread starter Takuya Matsumoto
  • Start date Start date
T

Takuya Matsumoto

Greetings to all,

I really appreciate the support from this community and I've made some
advancements, but again I'm hitting a wall...

I'm trying to write a program in C# that passes an option to another EXE so
that the second program knows what to do.
I belive the syntax is like below, but the problem arises when I add the
option; it does not find the exe file.

System.Diagnostics.Process.Start("c:\program files\program\sample.exe"
/option:"doSomething");

As a test, I tried "Run" option of Windows as below:
"c:\program files\program\sample.exe" /option:"doSomething"
and this works fine.

I'm puzzled as to what the problem is.
What am I doing wrong?

Thanks very much for your help!

Cheers,

Takuya
 
Remember the syntax of strings in C#. I think you want to type this:

System.Diagnostics.Process.Start(
"\"c:\\Program FIles\\Program\\Sample.exe\" /option:\"doSomething\"");

That is, put \ before every \ or " that occurs within a string.
 
Remember the syntax of strings in C#. I think you want to type this:
System.Diagnostics.Process.Start(
"\"c:\\Program FIles\\Program\\Sample.exe\" /option:\"doSomething\"");

That is, put \ before every \ or " that occurs within a string.


Woops, my typing mistake.
I had actually done so.

Cheers,

Takuya
 
<irrelevant newsgroups removed>
Takuya Matsumoto said:
Greetings to all,

<snipped>

I'm trying to write a program in C# that passes an option to another EXE so
that the second program knows what to do.
I belive the syntax is like below, but the problem arises when I add the
option; it does not find the exe file.

System.Diagnostics.Process.Start("c:\program files\program\sample.exe"
/option:"doSomething");

<snipped>

Cheers,

Takuya

The Process class' "Start" method has an override specifically for supplying
arguments to the executable being started. In your case, the syntax would
be:
System.Diagnostics.Process.Start("C:\\Program Files\\Program\\Sample.exe",
"/option:\"doSomething\"");

Good luck.
 
hi,

i think you can also put an @ before your string, then the echap char would
be automatic.
@"c:\program files\program\sample.exe" would work i suppose.

ROM



"Michael A. Covington" <[email protected]> a
ecrit dans le message de #[email protected]...
Remember the syntax of strings in C#. I think you want to type this:

System.Diagnostics.Process.Start(
"\"c:\\Program FIles\\Program\\Sample.exe\" /option:\"doSomething\"");

That is, put \ before every \ or " that occurs within a string.
 
I don't have it in front of me, but I was pretty sure that there is an
overload for process.start that allows you to pass a command line argument.
It's not all passed as one string. The overloads second parameter is an
object array if I remember correctly.

Phil
 
Back
Top