我有这个简单的红宝石脚本:
redcricket@dev-006:~$ cat simple.rb
#!/usr/local/bin/ruby
IO.popen 'ls -l', 'r+' do |f|
puts f.gets
end
当我运行它时,我得到的唯一输出是这个......
redcricket@dev-006:~$ ./simple.rb
total 32
......我所期望的是这个......
redcricket@smp-mig-dev-006:~$ ls -l
total 32
drwxr-xr-x 4 redcricket co 4096 Dec 5 12:23 applications
-rw-r--r-- 1 redcricket co 464 Oct 5 16:23 config
drwxr-xr-x 72 redcricket co 4096 Dec 5 15:11 docs
drwxr-xr-x 3 root root 4096 Dec 5 12:14 oradiag_root
drwxr-xr-x 5 redcricket co 4096 Dec 5 16:22 platform
-rwxr-xr-x 1 redcricket co 373 Dec 5 16:30 process_yum_output.rb
-rwxr-xr-x 1 redcricket co 2159 Nov 28 16:24 SetupSSHPK.sh
-rwxr-xr-x 1 redcricket co 142 Dec 5 16:31 simple.rb
...我想我需要以某种方式迭代 f.gets 吗?
谢谢!