I want to run an executable from a ruby rake script, say foo.exe
I want the STDOUT and STDERR outputs from foo.exe to be written directly to the console I’m running the rake task from.
When the process completes, I want to capture the exit code into a variable. How do I achieve this?
I’ve been playing with backticks, process.spawn, system but I cant get all the behaviour I want, only parts
Update: I’m on Windows, in a standard command prompt, not cygwin
systemgets theSTDOUTbehaviour you want. It also returnstruefor a zero exit code which can be useful.$?is populated with information about the lastsystemcall so you can check that for the exit status:I’ve used a combination of these things in
Runner.execute_commandfor an example.