Passing an array of arguments on the command line

I examined this question about passing command line arguments in C # .

But in my case, I have to pass an array of parameters to the calling .exe file.

eg.

var arr = new string[] {"Item title","New task","22","High Priority"} 

Is it possible to use Process.Start() with an EXE route along with an array

I have a .exe path

 const string path = @"C:\Projects\Test\test.exe"; 

thanks

+6
source share
3 answers

Please try the following:

  var arr = new string[] {"Item title", "New task", "22", "High Priority"}; const string path = @"C:\Projects\Test\test.exe"; const string argsSeparator = " "; string args = string.Join(argsSeparator, arr); Process.Start(path, args); 
+2
source

It is not possible to pass an array as an argument, you can pass a string using Comma Separator:

  ProcessStartInfo info = new ProcessStartInfo(); info.Arguments = "Item title,New task,22,High Priority" 
0
source

One parameter is to put the array on one line, so the method is considered as one of the arguments. In your method, you can parse this one argument. Sort of:

 "Item title, New task, 22, High Priority" 

You can use your existing array by doing the following:

 var arrAsOneString = string.Join(", ", arr); 

Inside your method, do:

 var values = argument.Split(',').Select(x => x.Trim()); 

I added cropping to get rid of the spaces.

0
source

Source: https://habr.com/ru/post/924712/


All Articles