ruby - Kernel# gets stuck and Kernel#system does not when issuing gzip without any options -


long story short, i've been working on project , noticed when use:

1.9.3p392 :001 > `gzip` irb::abort: abort interrupt!     (irb):1:in `call'     (irb):1:in ``'     (irb):1     /usr/local/rvm/rubies/ruby-1.9.3-p392/bin/irb:16:in `<main>' 

it wait indefinitely until ctrl + c.

although, when use:

1.9.3p392 :047 > system('gzip') gzip: compressed data not written terminal. use -f force compression. help, type: gzip -h  => false 

it continue without me using ctrl + c

why using backticks stop process continuing?

the backticks operator implicitly redirects standard output of resulting subshell (which capture subshell's output) while system doesn't. can observe same hang using system follows:

system('gzip > /tmp/foo') 

this explicitly captures standard output , hang in same way.

when gzip has output redirected wait input until eof or other signal received. without output redirection issue error message mention. can same effect regular bash shell:

$ gzip gzip: compressed data not written terminal. use -f force compression. help, type: gzip -h 

and:

$ gzip > /tmp/foo ... 

where ... indicates gzip hang until receives appropriate signal.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -