Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass multiple arguments to a newly created process in C# .net?

Tags:

c#

How can I pass multiple arguments to a newly created process in C#?

Also which class (Process or ProcessStartInfo or MyProcess) in should I use in executing a program, with the condition of passing multiple arguments to the newly created/executed process?

As is I have the equivalent (Borland) C++ code for the same task, which is as follows:

spawnv(P_NOWAITO,Registry->ReadString("Downloader").c_str(),arglist);

where arglist is a char pointer array and Registry->ReadString("Downloader").c_str(), is the program to execute.

like image 483
Asad Avatar asked Aug 12 '10 02:08

Asad


People also ask

How to pass multiple arguments into a thread in C?

/* Code Listing 6.9: Passing multiple arguments to a thread requires grouping them into a struct */ /* Assume we have: struct thread_args { int first; const char *second; }; */ struct thread_args *args = malloc (sizeof (struct thread_args)); args->first = 5; args->second = "Hello"; /* Note that the data structure ...

Can you pass multiple arguments to a method?

We pass arguments in a function, we can pass no arguments at all, single arguments or multiple arguments to a function and can call the function multiple times.

How do I pass multiple arguments to a thread function?

For cases where multiple arguments must be passed, this limitation is easily overcome by creating a structure which contains all of the arguments, and then passing a pointer to that structure in the pthread_create() routine. All arguments must be passed by reference and cast to (void *).

How do I pass multiple arguments in Processstartinfo?

Just use "&&" in your command line. Save this answer.


2 Answers

In order to pass multiple command line arguments you should separate each with a space and surround it in quotes in case the argument itself contains a space.

string[] args = { "first", "second", "\"third arg\"" };
Process.Start("blah.exe", String.Join(" ", args));
like image 114
Josh Avatar answered Oct 18 '22 20:10

Josh


Process.Start( "program.exe", "arg1 arg2 arg3" );
like image 21
Jerod Houghtelling Avatar answered Oct 18 '22 20:10

Jerod Houghtelling