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?
views:
45answers:
2
+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
2010-08-17 11:23:21
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
2010-08-17 11:37:59
@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
2010-08-17 12:00:33
+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
2010-08-17 15:30:41