Question

Just wondering if there is another way to handle this as the arguments are getting split when passing in like this:

System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(fileName);
psi.Arguments = @"c:\dir1\dir2\dir3\file1.txt";
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();

Then, in the new application when we access Environment.GetCommandLinesARgs() We are getting an array that looks like this:

string[] arr = {"filename","c:\dir1","dir2","dir3", "file1.txt"}
Was it helpful?

Solution

The problem is that you aren't passing the arguments in correctly.

You need to include quotes around the path, like this:

psi.Arguments = @"""c:\dir1\dir2\dir3\file1.txt""";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top