top of page

[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 All

[C#] Inconsistent accessibility

Phenomenon In C #, the following code causes a title compilation error. This error occurs when, for example, the class is private but the...

Comments


category

Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png
bottom of page