Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass multiple argments with process.startInfo.Arguments

I have this peace of code here:

void Main(string[] args) {
   string[] ARRAY = new string[2];
   ARRAY[0] = "1";
   ARRAY[1] = "2";
   
   Process process = new Process();
   process.startInfo.FileName = @"PATH"; //runs itself
   process.startInfo.Arguments = ARRAY;
   process.Start();
}

I need the program to pass whole array to next instance itsself (it is able to receive), but i keep getting that it requires string. Is there any workaround?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

process.startInfo.Arguments is of type string and you are trying to pass array of string to it.

public string Arguments { get; set; }

Instead of passing entire array, you have to convert it to the string first and then assign it to process.startInfo.Arguments

...
process.startInfo.Arguments = string.Join(" ", ARRAY);

Your final code will look like,

void Main(string[] args) {
   string[] ARRAY = new string[2];
   ARRAY[0] = "1";
   ARRAY[1] = "2";
   
   Process process = new Process();
   process.startInfo.FileName = @"PATH"; //runs itself
   process.startInfo.Arguments = string.Join(" ", ARRAY);
   process.Start();            //^^^^^^^^^^^^^^^ This is what you need
}

For more details: string.Join()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading