Joel P. wrote in post #1129747:
From the IRB responses, it looks like the command “python -V” is
printing the output and returning an empty string, I don’t think there’s
anything wrong with your code, it’s how “python -V” responds.
Of course, someone else may have a better understanding of this.
Edit: Nice catch as usual, Robert! I thought that command was getting
through, since you can see the response given: “Python 3.3.2”
Thank you for that information, it definitely sheds some light on that
whole bit. I wouldn’t have known what to search for to find that out.
Justin C. wrote in post #1129754:
On 12/05/2013 09:20 AM, Robert K. wrote:
=> “C:/python/python332”
Certainly you can nest string interpolation, although it’s silly in this
case (and most cases I’ve seen):
2.0.0p247 :001 > command = “ruby”
=> “ruby”
2.0.0p247 :002 > #{"#{command} -v"}
=> “ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]\n”
In any case, OP’s issue is that “ruby -v” outputs to stdout, and “python
-V” outputs to stderr which is not captured by backticks:
$ ruby -v > /dev/null
$ python -V > /dev/null
Python 2.7.5
$ python -V &> /dev/null
$
A simple way to deal with this would be to use Open3:
$ irb
2.0.0p247 :001 > require ‘open3’
=> true
2.0.0p247 :002 > Open3.capture2e(“ruby -v”)
=> [“ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]\n”,
#<Process::Status: pid 16154 exit 0>]
2.0.0p247 :003 > Open3.capture2e(“python -V”)
=> [“Python 2.7.5\n”, #<Process::Status: pid 16167 exit 0>]
-Justin
Thank you Justin, yes, I use the nested interpolation to help with the
commands and save code, but I will look into the Open3 and see what I
can do with that. Thank you for the help. I’ll post back once I figure
out what I need to do. I’m also on Windows, I’m not sure how I’d test
the StdOut, and StdErr with Command Prompt.