Well since it probably supports command line arguments, you could always use 'system' method
Pass "w" as second argument: IO.popen("maxima", "w")
What about readlines.last?
Hm I'm not sure why does it freeze. You could try max.to_a.last or if all else fails try just skipping unnecessary lines using while loop