# IO.popen doesn't fail for non-existent command

**URL:** <https://www.ruby-forum.com/t/io-popen-doesnt-fail-for-non-existent-command/90959>\
**Category:** Development\
**Created:** [April 3, 2007, 12:27pm UTC](https://www.ruby-forum.com/t/io-popen-doesnt-fail-for-non-existent-command/90959 "2007-04-03T12:27:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 3, 2007, 12:27pm UTC](https://www.ruby-forum.com/t/io-popen-doesnt-fail-for-non-existent-command/90959/1 "2007-04-03T12:27:09Z")

</div>

e$B$J$+$@$G$9!#e(B

[http://bts.vinelinux.org/guest.cgi?project=VineLinux&action=view\_report&id=481](http://bts.vinelinux.org/guest.cgi?project=VineLinux&action=view_report&id=481)  
e$B!Ve(B481: ri e$B$Ge(B command not found:  
pagere$B!W$K4XO"$7$?OC$G$9$,!“e(B  
IO.popene$B$KB8:\_$7$J$$%3%^%s%I$r;XDj$7$?$H$-$K%(%i!\<$K$J$i$J$$$Ne(B  
e$B$O!”\>/$J$/$H$be(B1.9e$B$G%P%0$@$H;W$$$^$9!#e(B

- io.c (popen\_exec): should not close close-on-exec fds.

# Index: io.c

— io.c (revision 12141)  
+++ io.c (working copy)  
@@ -3041,4 +3041,7 @@ popen\_exec(void \*pp)  
popen\_redirect(p);  
for (fd = 3; fd \< NOFILE; fd++) {  
+#ifdef FD\_CLOEXEC

- if (fcntl(fd, F\_GETFD) & FD\_CLOEXEC) continue;  
+#endif  
close(fd);  
}

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 3, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/io-popen-doesnt-fail-for-non-existent-command/90959/2 "2007-04-03T17:35:34Z")

</div>

e$B$J$+$@$G$9!#e(B

At Tue, 3 Apr 2007 19:26:15 +0900,  
removed\_email\_address@domain.invalid wrote in [ruby-dev:30679]:

> [http://bts.vinelinux.org/guest.cgi?project=VineLinux&action=view\_report&id=481](http://bts.vinelinux.org/guest.cgi?project=VineLinux&action=view_report&id=481)  
> e$B!Ve(B481: ri e$B$Ge(B command not found: pagere$B!W$K4XO"$7$?OC$G$9$,!“e(B  
> IO.popene$B$KB8:\_$7$J$$%3%^%s%I$r;XDj$7$?$H$-$K%(%i!\<$K$J$i$J$$$Ne(B  
> e$B$O!”\>/$J$/$H$be(B1.9e$B$G%P%0$@$H;W$$$^$9!#e(B

1.8e$BMQ$K!"e(Bri\_display.rbe$B$N%Q%C%A$G$9!#$d$C$F$k$3$H$Oe(B1.9e$B$HF1$8$G$9!#e(B

# Index: lib/rdoc/ri/ri\_display.rb

— lib/rdoc/ri/ri\_display.rb (revision 12136)  
+++ lib/rdoc/ri/ri\_display.rb (working copy)  
@@ -211,5 +211,30 @@ class DefaultDisplay  
def setup\_pager  
unless @options.use\_stdout

- 

```
 for pager in [ENV['PAGER'], "less", "more", 'pager' 

```

].compact.uniq

- 

```
 pagers = [ENV['PAGER'], "less", "more", 'pager' ].compact.uniq

```

- 

```
 begin

```

- require ‘fcntl’
- if defined?(Fcntl::F\_SETFD) and defined?(Fcntl::FD\_CLOEXEC)
- r, w = IO.pipe
- w.fcntl(Fcntl::F\_SETFD, Fcntl::FD\_CLOEXEC)
- unless f = IO.popen(“-”, “w”)
- 

```
 r.close

```

- 

```
 for pager in pagers

```

- 

```
   exec(pager) rescue nil

```

- 

```
 end

```

- 

```
 w.write("\0")

```

- 

```
 w.close

```

- 

```
 exit!

```

- end
- w.close
- w = nil
- return f unless r.getc
- f.close
- pagers.clear
- end
- 

```
 rescue LoadError, Errno::ENOENT, NotImplementedError

```

- 

```
 ensure

```

- [r, w].each {|f| (f.close if f and !f.closed?) rescue nil}
- 

```
 end

```

- 

```
 for pager in pagers
   return IO.popen(pager, "w") rescue nil
 end

```

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 3, 2007, 6:18pm UTC](https://www.ruby-forum.com/t/io-popen-doesnt-fail-for-non-existent-command/90959/3 "2007-04-03T18:18:38Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30679] IO.popen doesn’t fail for non-existent  
command”  
on Tue, 3 Apr 2007 19:26:15 +0900, removed\_email\_address@domain.invalid writes:

|http://bts.vinelinux.org/guest.cgi?project=VineLinux&action=view\_report&id=481  
|e$B!Ve(B481: ri e$B$Ge(B command not found: pagere$B!W$K4XO"$7$?OC$G$9$,!“e(B  
|IO.popene$B$KB8:\_$7$J$$%3%^%s%I$r;XDj$7$?$H$-$K%(%i!\<$K$J$i$J$$$Ne(B  
|e$B$O!”\>/$J$/$H$be(B1.9e$B$G%P%0$@$H;W$$$^$9!#e(B  
|  
|\* io.c (popen\_exec): should not close close-on-exec fds.

e$B%3%\_%C%H$7$F$/$@$5$$!#e(B1.8e$B$Ke(B[ruby-dev:30680]e$B$rEv$F$k$+$I$&$+e(B  
e$B$Oe(Bknue$B$5$s$K$\*G$$;$7$^$9!#e(B

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 5, 2007, 4:03am UTC](https://www.ruby-forum.com/t/io-popen-doesnt-fail-for-non-existent-command/90959/4 "2007-04-05T04:03:38Z")

</div>

At Wed, 4 Apr 2007 00:34:47 +0900,  
Nobuyoshi N. wrote:

> ãªã‹ã ã§ã™ã€‚
> 
> At Tue, 3 Apr 2007 19:26:15 +0900,  
> removed\_email\_address@domain.invalid wrote in [ruby-dev:30679]:
> 
> > [http://bts.vinelinux.org/guest.cgi?project=VineLinux&action=view\_report&id=481](http://bts.vinelinux.org/guest.cgi?project=VineLinux&action=view_report&id=481)  
> > ã€Œ481: ri ã§ command not found: pagerã€ã«é–¢é€£ã—ãŸè©±ã§ã™ãŒã€  
> > IO.popenã«å­˜åœ¨ã—ãªã„ã‚³ãƒžãƒ³ãƒ‰ã‚’æŒ‡å®šã—ãŸã¨ãã«ã‚¨ãƒ©ãƒ¼ã«ãªã‚‰ãªã„ã®  
> > ã¯ã€å°‘ãªãã¨ã‚‚1.9ã§ãƒã‚°ã ã¨æ€ã„ã¾ã™ã€‚
> 
> 1.8ç”¨ã«ã€ri\_display.rbã®ãƒ‘ãƒƒãƒã§ã™ã€‚ã‚„ã£ã¦ã‚‹ã“ã¨ã¯1.9ã¨åŒã˜ã§ã™ã€‚

ã€€å…¥ã‚Œã¦ãã ã•ã„ã€‚

ã€€ã—ã‹ã—ã€1.8ã ã¨é¢å€’ã§ã™ã­ã€‚ã§ãã‚Œã° popen ã”ã¨backportã§ãã‚Œã°  
ã„ã„ã‚“ã§ã™ãŒã€ã¡ã‚‡ã£ã¨å¤§ã‹ãŒã‚Šã§ã™ã‹ã€‚

–  
/  
/\_\_ \_\_ [Akinori.org](http://Akinori.org) / [MUSHA.org](http://MUSHA.org)  
/ ) ) ) ) / [FreeBSD.org](http://FreeBSD.org) / [Ruby-lang.org](http://Ruby-lang.org)  
Akinori MUSHA aka / (\_ / ( (\_\_( @ [iDaemons.org](http://iDaemons.org) / and.or.jp

“Different eyes see different things,  
Different hearts beat on different strings –  
But there are times for you and me when all such things agree”
