1

希望生成一个可以向其发出多个命令的进程。希望调用一个 bat 文件来为这个生成的进程设置一些环境变量,然后利用这些变量而不影响其他进程等

在 POPEN4 结束,这似乎完全符合我的要求,但是在 stderr.rewind 的倒带时看到错误

使用下面 popen4 提供的示例并看到以下输出

C:\>ruby envread.rb
pid        : 4452
stdout     : Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\>echo hello world!
hello world!

C:\>echo ERROR!  1>&2

C:\>
stderr     : ERROR!
C:/Ruby193/lib/ruby/gems/1.9.1/gems/POpen4-0.1.4/lib/popen4.rb:60:in `rewind': invalid argument (Errno::EINVAL)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/POpen4-0.1.4/lib/popen4.rb:60:n `block in popen4'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/win32-open3-19-0.0.2/lib/win32/open3.rb:6:in `call'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/win32-open3-19-0.0.2/lib/win32/open3.rb:6:in `block in popen4'
    from C:/Ruby193/lib/ruby/1.9.1/open3.rb:208:in `popen_run'
    from C:/Ruby193/lib/ruby/1.9.1/open3.rb:90:in `popen3'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/win32-open3-19-0.0.2/lib/win32/open3.rb:5:in `popen4'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/POpen4-0.1.4/lib/popen4.rb:48:in `popen4'
    from envread.rb:8:in `<main>'

所以为了澄清我必须使用wind32-open3-19,因为我使用的是ruby 1.9。

阅读 1.9 的 IO 文档,它说倒带不能用于流?我看到像 Aruba 这样的宝石使用 stderr 的倒带...

> rewind → 0 click to toggle source Positions ios to the beginning of
> input, resetting lineno to zero.
> 
> f = File.new("testfile") f.readline   #=> "This is line one\n"
> f.rewind     #=> 0 f.lineno     #=> 0 f.readline   #=> "This is line
> one\n" Note that it cannot be used with streams such as pipes, ttys,
> and sockets.

我究竟做错了什么?

4

0 回答 0