IO.popen exit the program when it failed

i have been trying to recieved the output of a command with IO.popen and
it works great but if i place a unknown command to the system the ruby
program terminates.

def comando ( inputcmd )
f = IO.popen(inputcmd)
output = f.readlines
return output
end

#########################################################
there is a loop calling the method like this:
#########################################################

  cliente.puts "Escriba el comando a ejecutar por cmd.exe: "
  inputcmd = cliente.gets
  cliente.puts comando( inputcmd )

any help will be appreciated!!

Thank you!

i found the solution on the forum :smiley:

i use: IO.popen(cmdline + " 2>&1", “w+”)

but now i have another problem, if i run a command that needs several
lines
the output comes back incomplete.
Any ideas?

there is a way to increase the size of the
buffer? does it affect if the variable its been trransfer with
TCPSockets??

Daniel Flores wrote:

i found the solution on the forum :smiley:

i use: IO.popen(cmdline + " 2>&1", “w+”)

but now i have another problem, if i run a command that needs several
lines
the output comes back incomplete.
Any ideas?

use .read instead of .gets (?)

-r

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs