rubyw.exe and using Open3 for an external programm requiring STDOUT STDERR

28 views
Skip to first unread message

Ralf Vitasek

unread,
May 4, 2015, 9:24:16 AM5/4/15
to rubyin...@googlegroups.com
Hello group!

I wonder if anyone has any experience or can tell me about the side effects i'm experiencing with using rubyw.exe to run thin application servers and now my attempts to run a command line tool via Open3.popen3 but since that tool needs to write to STDERR (for no obvious reason) i don't get any result from said tool when started from within a rubyw.exe process.

As soon as i run my code from a cmd.exe spawned "console window" or s plain rails console everything is fine.
My first attempts involved simple system() calls to run the command line tool which pretty much acted the same what i'm now trying with Open3. I thought the interface to stdin/stout/stderr that Open3 provides would allow me to run the tool but it seems that by the fact that rubyw.exe already has no stdout/stderr i already have Open3 in a crippled state.

This was observed on a quite old system running Rails 3.2 with "ruby 1.9.3p385 (2013-02-06) [i386-mingw32]" (update to Rails 4 and Ruby 2.1 is due in a couple of weeks).

So mainly the question is am i really out of options with Open3 when rubyw.exe is used?

Regards,

Ralf


Justin Baker

unread,
May 4, 2015, 5:02:00 PM5/4/15
to rubyin...@googlegroups.com
Hey, see inline comments below.


On Monday, May 4, 2015 at 8:24:16 AM UTC-5, Ralf Vitasek wrote:
Hello group!

I wonder if anyone has any experience or can tell me about the side effects i'm experiencing with using rubyw.exe to run thin application servers and now my attempts to run a command line tool via Open3.popen3 but since that tool needs to write to STDERR (for no obvious reason) i don't get any result from said tool when started from within a rubyw.exe process.

I don't think `rubyw.exe` even provides `stdin`, `stdout`, or `stderr`.
 
As soon as i run my code from a cmd.exe spawned "console window" or s plain rails console everything is fine.
My first attempts involved simple system() calls to run the command line tool which pretty much acted the same what i'm now trying with Open3. I thought the interface to stdin/stout/stderr that Open3 provides would allow me to run the tool but it seems that by the fact that rubyw.exe already has no stdout/stderr i already have Open3 in a crippled state.

Unfortunately it looks like it may be working as intended. =/ 

This was observed on a quite old system running Rails 3.2 with "ruby 1.9.3p385 (2013-02-06) [i386-mingw32]" (update to Rails 4 and Ruby 2.1 is due in a couple of weeks).

So mainly the question is am i really out of options with Open3 when rubyw.exe is used?

What is it you're trying to accomplish by running it with `rubyw.exe`? Maybe there is an alternative?

Justin

Dušan D. Majkić

unread,
May 5, 2015, 2:59:54 AM5/5/15
to rubyin...@googlegroups.com
​This works on ​2.1.6

require "open3"
require 'fiddle/import'
require 'fiddle/types'

module WinAPI
  extend Fiddle::Importer
  dlload 'user32.dll'
  include Fiddle::BasicTypes
  include Fiddle::Win32Types
  typealias 'LPCWSTR', 'wchar_t*'
  extern "int MessageBoxW(HWND, LPCWSTR, LPCWSTR, DWORD)"
  MB_OK = 0
end

def message_box text, title = "", buttons = WinAPI::MB_OK
  WinAPI::MessageBoxW(0, text.encode!('UTF-16LE'), title.encode!('UTF-16LE'), buttons)
end


stderr_and_stdout, status = Open3.capture2e("dir", binmode: true)
# stdout_str, stderr_str, status = Open3.capture3([env,] cmd... [, opts])

message_box stderr_and_stdout




--
You received this message because you are subscribed to the Google Groups "RubyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyinstalle...@googlegroups.com.
To post to this group, send email to rubyin...@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyinstaller.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages