How to redirect STDOUT of subscript into variable in ruby 2.1.6 -
here full code far:
if argv.size == 0 print "set library name parameter" else dir = argv[0] begin dir.chdir "#{dir}" rescue print "no such library" else filelist = dir.glob "*.rb" outfile = "result" = 0 while < filelist.size filename = filelist[i] output = load "./#{filename}" if output == 1 file.open(outfile, 'a+') { |file| file.write("#{filename}")} end += 1 end end end
the subscripts i'm trying run can either contain this: print "1"
or this: print "0"
.
i want write "result" file
filename :: ok
if print "1"
, ,
filename :: wrong
if print "2"
.
my problem output
equals true
instead of 1
or 0
. how redirect subscript's stdout
output
variable?
this should give output :
output = `ruby #{filename}`
note : returns string, comparing output number. necessary conversions.
Comments
Post a Comment