tags:

views:

45

answers:

2

I'm trying to run some commands, like rails test, using a C# command line. I tried using http://stackoverflow.com/questions/206323/how-to-execute-command-line-in-c-get-std-out-results but I'll need full path to the rails executable for that to work. Is there any alternative that will find work just like the windows command line does?

+1  A: 

I believe if you have UseShellExecute set to true in the ProcessStartInfo used to start the process, it'll use the path. Haven't checked it yet - will do so when I get a chance.

Jon Skeet
Thanks for the answer. It seems to do that - but I'm unable to read the output when `UseShellExecute' is `true`. `RedirectStandardOutput' requires `UseShellExecute` set to false.
Adam
@Adam: Yes, it seems you can't have it both ways... Could you get the rails test program to dump its results to a log file which you can read?
Jon Skeet
+1  A: 

If you can P/Invoke, you could locate the executable with PathFindOnPath. A quick google doesn't show a C# equivalent.

without P/Invoke, Environment.GetEnvironmentVariable("Path").Split(";") should give you a list of paths to probe.

However, this is not the entire resolution used by ShellExecute or even the console.

peterchen