ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-dev:45812] Re: [ruby-cvs:43389] nobu:r36213 (trunk): popen: shell commands with envvar
       [not found] <20120625064206.BFD403ED43@fluorine.ruby-lang.org>
@ 2012-06-25  8:13 ` Tanaka Akira
  2012-06-25  8:22   ` [ruby-dev:45813] " KOSAKI Motohiro
  2012-06-26 14:22   ` [ruby-dev:45853] " Nobuyoshi Nakada
  0 siblings, 2 replies; 3+ messages in thread
From: Tanaka Akira @ 2012-06-25  8:13 UTC (permalink / raw
  To: ruby developers list

2012/6/25  <nobu@ruby-lang.org>:
> nobu    2012-06-25 15:42:05 +0900 (Mon, 25 Jun 2012)
>
>  New Revision: 36213
>
>  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36213
>
>  Log:
>    popen: shell commands with envvar
>
>    * io.c (is_popen_fork): check if fork and raise NotImplementedError if
>      unavailable.
>    * io.c (rb_io_s_popen): allow shell commands with modified environment
>      variables.

IO.popen([str]) の str が shell の解釈を受けるようになって
おどろいたのですが、なにか話があったんでしょうか。

  % ./ruby -ve 'IO.popen(["echo foo"]){|f| p f.read }'
  ruby 2.0.0dev (2012-06-25 trunk 36211) [x86_64-linux]
  -e:1:in `popen': No such file or directory - echo foo (Errno::ENOENT)
	  from -e:1:in `<main>'

  % ./ruby -ve 'IO.popen(["echo foo"]){|f| p f.read }'
  ruby 2.0.0dev (2012-06-25 trunk 36214) [x86_64-linux]
  "foo\n"

とりあえず、現在はドキュメントと整合していない状態になっています。

IO.popen のドキュメントには

 *      [env, cmdname, arg1, ..., opts]          : command name and
zero or more arguments (no shell)

とか、

 *  If <i>cmd</i> is an +Array+ of +String+,
 *  then it will be used as the subprocess's +argv+ bypassing a shell.

などと書いてあるので。
-- 
[田中 哲][たなか あきら][Tanaka Akira]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-dev:45813] Re: [ruby-cvs:43389] nobu:r36213 (trunk): popen: shell commands with envvar
  2012-06-25  8:13 ` [ruby-dev:45812] Re: [ruby-cvs:43389] nobu:r36213 (trunk): popen: shell commands with envvar Tanaka Akira
@ 2012-06-25  8:22   ` KOSAKI Motohiro
  2012-06-26 14:22   ` [ruby-dev:45853] " Nobuyoshi Nakada
  1 sibling, 0 replies; 3+ messages in thread
From: KOSAKI Motohiro @ 2012-06-25  8:22 UTC (permalink / raw
  To: ruby developers list

On Mon, Jun 25, 2012 at 4:13 AM, Tanaka Akira <akr@fsij•org> wrote:
> 2012/6/25  <nobu@ruby-lang.org>:
>> nobu    2012-06-25 15:42:05 +0900 (Mon, 25 Jun 2012)
>>
>>  New Revision: 36213
>>
>>  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36213
>>
>>  Log:
>>    popen: shell commands with envvar
>>
>>    * io.c (is_popen_fork): check if fork and raise NotImplementedError if
>>      unavailable.
>>    * io.c (rb_io_s_popen): allow shell commands with modified environment
>>      variables.
>
> IO.popen([str]) の str が shell の解釈を受けるようになって
> おどろいたのですが、なにか話があったんでしょうか。
>
>  % ./ruby -ve 'IO.popen(["echo foo"]){|f| p f.read }'
>  ruby 2.0.0dev (2012-06-25 trunk 36211) [x86_64-linux]
>  -e:1:in `popen': No such file or directory - echo foo (Errno::ENOENT)
>          from -e:1:in `<main>'
>
>  % ./ruby -ve 'IO.popen(["echo foo"]){|f| p f.read }'
>  ruby 2.0.0dev (2012-06-25 trunk 36214) [x86_64-linux]
>  "foo\n"
>
> とりあえず、現在はドキュメントと整合していない状態になっています。
>
> IO.popen のドキュメントには
>
>  *      [env, cmdname, arg1, ..., opts]          : command name and
> zero or more arguments (no shell)
>
> とか、
>
>  *  If <i>cmd</i> is an +Array+ of +String+,
>  *  then it will be used as the subprocess's +argv+ bypassing a shell.
>
> などと書いてあるので。

ちょっとオフトピックになってしまいますが、挙動が変わる奴はチケット切ってから
コミットして欲しいです。いつのまにか挙動が変わってるのはしんどすぎます。

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-dev:45853] Re: [ruby-cvs:43389] nobu:r36213 (trunk): popen: shell commands with envvar
  2012-06-25  8:13 ` [ruby-dev:45812] Re: [ruby-cvs:43389] nobu:r36213 (trunk): popen: shell commands with envvar Tanaka Akira
  2012-06-25  8:22   ` [ruby-dev:45813] " KOSAKI Motohiro
@ 2012-06-26 14:22   ` Nobuyoshi Nakada
  1 sibling, 0 replies; 3+ messages in thread
From: Nobuyoshi Nakada @ 2012-06-26 14:22 UTC (permalink / raw
  To: ruby developers list

なかだです。

At Mon, 25 Jun 2012 17:13:56 +0900,
Tanaka Akira wrote in [ruby-dev:45812]:
> とりあえず、現在はドキュメントと整合していない状態になっています。

すいません、自分で入れた仕様を忘れてました。

何がしたいかというと環境変数を指定してpopenをしたい、ただしコマ
ンドはArrayにはわかれていない単一の文字列、といったところです。
例えばgitがページャーを実行するのにやっているようなことです。

  IO.popen("LESS=RSs #{ENV['PAGER']}", "w")

今のところenvやexec optionを指定するのはcmdがArrayでないとできま
せんが、Arrayの外に出してしまうというのを考えました。

  IO.popen({"LESS"=>"RSs"}, ENV['PAGER'], "w")
  IO.popen({"LANG"=>"C"}, "ls non-existent", err:[:child, :out])

もちろんArrayを使っても同じです。

  IO.popen({"LANG"=>"C"}, ["ls", "non-existent"], err:[:child, :out])

パッチは https://github.com/ruby/ruby/pull/134 です。

-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-06-26 14:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20120625064206.BFD403ED43@fluorine.ruby-lang.org>
2012-06-25  8:13 ` [ruby-dev:45812] Re: [ruby-cvs:43389] nobu:r36213 (trunk): popen: shell commands with envvar Tanaka Akira
2012-06-25  8:22   ` [ruby-dev:45813] " KOSAKI Motohiro
2012-06-26 14:22   ` [ruby-dev:45853] " Nobuyoshi Nakada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).