[C#] Process.start ends with exit code 2
Problem
When I execute an external program with Process.start, it does not work as expected and exits with exit code 2 (no exceptions).
Cause
I passed the path of the executable file as a command line argument, but there was a space in the path. The command line argument is regarded as another argument after the blank.
solution
Command line arguments are not separated by spaces when enclosed in "". You need to prefix "" to make "a string.
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo();
psi.FileName = "python.exe";
psi.Arguments = @"""C:\my folder\test.py"""; //here
System.Diagnostics.Process.Start(psi);
Lastly
I was addicted to such a mediocre mistake ...
When I name the folder myself, I can't put a space, but the installation destination of visual studio has a space.
Recent Posts
See AllPhenomenon In C #, the following code causes a title compilation error. This error occurs when, for example, the class is private but the...
Comments