Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to use MinGW in my programming language. I only can run the binaries in C# if I specify the full path, even if I set it in the PATH environment variable. I'm using System.Diagnostics.Process class. Is there any way to know where MinGW is installed or how can I run it without specifying its path?
Posted
Updated 29-May-11 18:44pm
v2

1 solution

I don't think the modification of path environment variable is not working.

Would you try it again, more thoroughly. There is one delicate moment some miss. You're running some Shell application like Explorer or CMD.EXE and start other application as a child process. If you updated your path environment variable in between, your parent process remains not notified about the change. You need to re-start it for your modification to be taken into account.

Careful: I don't mean your application using MinGW, I mean some parent process (Shell or console) you use to start your application. Restart it.
Please check it up.

[EDIT]
To run a console application from you code, use System.Diagnostic.Process.Start, redirect standard input, output and error streams. See for more information: Custom Command Line program (Form)[^], ask a follow-up question if you face a problem.

—SA
 
Share this answer
 
v3
Comments
Monjurul Habib 29-May-11 18:34pm    
nice explanation ,my 5.
Sergey Alexandrovich Kryukov 29-May-11 18:36pm    
Thank you, Monjurul. Hope it helps OP.
--SA
Dávid Kocsis 30-May-11 0:47am    
It works correctly from console, but I want to run it with my application.
Sergey Alexandrovich Kryukov 30-May-11 13:43pm    
So, what's the problem? Please see updated solution. See MSDN code sample on redirected stream.
--SA
Dávid Kocsis 30-May-11 14:48pm    
I have solved the problem. Anyway thanks for helping. I had to set UseShellExecute to false otherwise the output will be in a new console window and when the program execution ends it will disappear, so I wont see the results. But its only finds the file in the PATH directories if UseShellExecute is true. So I find the file using Environment.GetEnvironmentVariable("PATH") method and simply specify the full path.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900