0

I'm trying to run some commands, like rails test, using a C# command line. I tried using 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?

Community
  • 1
  • 1
Dogbert
  • 212,659
  • 41
  • 396
  • 397

2 Answers2

1

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
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 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. – Dogbert Aug 17 '10 at 11:37
  • @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 Aug 17 '10 at 12:00
1

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
  • 40,917
  • 20
  • 104
  • 186