I want to capture the string that system("hostname") produces on windows
and store it in a variable. system() returns true or false. How can I
make it return the result (the hostname as a string) instead?
I want to capture the string that system("hostname") produces on windows
and store it in a variable. system() returns true or false. How can I
make it return the result (the hostname as a string) instead?
I want to capture the string that system("hostname") produces on
windows
and store it in a variable. system() returns true or false. How can I
make it return the result (the hostname as a string) instead?
If you want to catch all output including both STDOUT and STDERR you
should do following trick
output = `someprogram 2>&1`
So using OS pipes you redirect STDERR to STDOUT and then run application
and get STDOUT using `` function.
Except that the OP said he is on Windows, and unless he is using cygwin
to get bash/sh style redirection, that won't work. Starndard Error
isn't captured by any of the ruby IO/Exec processes that I can find.
If you want to catch all output including both STDOUT and STDERR you
should do following trick
output = `someprogram 2>&1`
So using OS pipes you redirect STDERR to STDOUT and then run application
and get STDOUT using `` function.
Except that the OP said he is on Windows, and unless he is using cygwin
to get bash/sh style redirection, that won't work. Starndard Error
isn't captured by any of the ruby IO/Exec processes that I can find.
I stand corrected. I did try it, but got it twisted up. Yet more
evidence that Windows has moved closer to a Unix syntax for the command
shell. Handy to know if I ever end up doing development on Windows.
···
Steve Martin wrote:
> Except that the OP said he is on Windows, and unless he is using cygwin
> to get bash/sh style redirection, that won't work. Starndard Error
> isn't captured by any of the ruby IO/Exec processes that I can find.