IO.popen exit the program when it failed

D

Daniel Flores

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!
 
D

Daniel Flores

i found the solution on the forum :D

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??
 
R

Roger Pack

Daniel said:
i found the solution on the forum :D

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top