reliable interactions with other processes?

51 views
Skip to first unread message

Jon

unread,
Feb 11, 2010, 5:19:04 PM2/11/10
to rubyin...@googlegroups.com
Looking into some problems due to this

http://github.com/mojombo/jekyll/blob/master/lib/jekyll/albino.rb#L64

and wondering what others are using to reliably interact with other processes via stdin, stdout, stderr on windows.

I'm aware of http://www.ruby-forum.com/topic/86976

FYI, on all our latest RC2's, the following seems runs fine, but is it reliable?

# open_three.rb
require 'open3'

puts "\nOpen3.popen3 non-block form..."
stdin, stdout, stderr, wait_thr = Open3.popen3('pygmentize -l ruby -f html')
stdin.write 'def foo; puts \'foo\';end'
stdin.close
puts stdout.read.strip
stdout.close
stderr.close

puts "\nOpen3.popen3 block form..."
Open3.popen3('pygmentize -l ruby -f html') do |i,o,e,w|
i.write 'def foo; puts \'foo\';end'
i.close
puts o.read.strip
end

Jon

skim

unread,
Feb 12, 2010, 2:32:31 PM2/12/10
to RubyInstaller
I'm having problems running pygments on my local server on Windows as
well.

According to this, http://github.com/mojombo/jekyll/issues/labels/fix#issue/76,
open4 library does not work on Windows. I tried applying his fix, but
it doesn't seem to work either.


On Feb 11, 2:19 pm, Jon <jon.for...@gmail.com> wrote:
> Looking into some problems due to this
>
> http://github.com/mojombo/jekyll/blob/master/lib/jekyll/albino.rb#L64
>
> and wondering what others are using to reliably interact with other processes via stdin, stdout, stderr on windows.
>

> I'm aware ofhttp://www.ruby-forum.com/topic/86976

Jon

unread,
Feb 12, 2010, 2:58:42 PM2/12/10
to rubyin...@googlegroups.com
> I'm having problems running pygments on my local server on Windows as
> well.
>
> According to this, http://github.com/mojombo/jekyll/issues/labels/fix#issue/76,
> open4 library does not work on Windows. I tried applying his fix, but
> it doesn't seem to work either.

I've had just a few minutes total to look into it, but a few more thoughts

1) Regex check at http://github.com/charliek/jekyll/blob/master/lib/jekyll/albino.rb#L64 needs to include 'mingw' so as to work with the RubyInstaller environments. I tend to use code like

require 'rbconfig'
...
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/

2) There may be 1.9 vs. 1.8 issues. The '@target' value (line 66 in above link) in my test comes in as a string Array like ["def foo; puts 'foo';end"] which doesn't play well with the pygmentize script. Should just be a string I believe.

3) Installing Pygments 1.2.2 via easy_install didn't create a wrapper for the Python script C:\Python26\Scripts\pygmentize and I hacked a simple C:\Python26\Scripts\pygmentize.bat with the following to get it to work (assuming C:\Python26\Scripts is on PATH)

@python.exe %~dp0pygmentize %*


Thanks for the info, and please post back when you think you've found something reliable. I'll also keep hacking, time permitting ;)

Jon

Jon

unread,
Feb 13, 2010, 12:13:59 PM2/13/10
to RubyInstaller
> I'm having problems running pygments on my local server on Windows as
> well.
>
> According to this,http://github.com/mojombo/jekyll/issues/labels/fix#issue/76,

> open4 library does not work on Windows.  I tried applying his fix, but
> it doesn't seem to work either.

I'm testing this patch which appears to be working on our 1.9.1 RC2.
Planning to look at how it works on our 1.8.6 and 1.8.7 RC2 installs.
The IO.popen code works on 1.8.7, 1.8.6, and 1.9.1 RC2.

http://gist.github.com/303561

skim

unread,
Feb 13, 2010, 2:22:44 PM2/13/10
to RubyInstaller
Awesome, I'll try it out!

skim

unread,
Feb 14, 2010, 3:54:55 AM2/14/10
to RubyInstaller
I installed Pygments 1.2.2 and used your patch, but I'm still unable
to get it to work on 1.8.7 RC2 and 1.9.1 RC2. Not sure what I'm doing
wrong, but this is the error message I'm getting:

Liquid error: No such file or directory - pygmentize -O encoding=utf-8
-l text -f html

Jon

unread,
Feb 14, 2010, 12:22:22 PM2/14/10
to rubyin...@googlegroups.com
> I installed Pygments 1.2.2 and used your patch, but I'm still unable
> to get it to work on 1.8.7 RC2 and 1.9.1 RC2. Not sure what I'm doing
> wrong, but this is the error message I'm getting:
>
> Liquid error: No such file or directory - pygmentize -O encoding=utf-8
> -l text -f html

Try putting a .bat wrapper around the pygmentize Python script and see if it works. I think the issue is that Pygments 1.2.2 doesn't provide the windows friendly .exe/.bat wrappers anymore with the result that the poor windows shell doesn't understand how to run 'pygmentize' as there's no file associations

Create a pygmentize.bat file in C:\Python26\Scripts (or wherever you installed Python) making sure its a peer to the Python pygmentize script and add the following line to it (note the 0 is a zero not the capital letter O):

@python.exe %~dp0pygmentize %*


Jon

p.s. - I think the patch can be simplified to always use IO.popen rather than open4 but need to check it on my Ubuntu load and an MRI mswin install from ruby-lang. I'd be very shocked if the core IO.popen didn't work on *nix systems. So I think if things go well for your testing and mine, we're close to cleaning up a patch to submit back to the Jekyll folks that will work for *nix and Windows :)

skim

unread,
Feb 14, 2010, 12:45:24 PM2/14/10
to RubyInstaller
Weird, I didn't change anything today and it started working. In any
case, I'm glad. Are you planning to write a blog post on this?

Jon

unread,
Feb 14, 2010, 1:11:16 PM2/14/10
to rubyin...@googlegroups.com
> Weird, I didn't change anything today and it started working. In any
> case, I'm glad. Are you planning to write a blog post on this?

Not until I test it out on Ubuntu and the mswin Ruby's from ruby-lang. Go for it :)

I'd like to see a solid patch get integrated into Jekyll's master. I think the "final" patch will turn out to be very simple...no need rbconfig checks or open4...use core's IO.popen, and tweak Jekyll's highlight tag to handle 1.8 and 1.9 cases...but I want to verify.

Jon

skim

unread,
Feb 14, 2010, 1:33:04 PM2/14/10
to RubyInstaller
I'd like to see a solid patch as well. Are you going to write it and
submit a pull request?

Jon

unread,
Feb 15, 2010, 10:21:29 AM2/15/10
to rubyin...@googlegroups.com
> I'd like to see a solid patch as well. Are you going to write it and
> submit a pull request?

Yes, as soon as I finish some more testing. Currently the IO.popen code is working on all the mingw32 versions and the 1.8.7 and 1.9.1 mswin versions from ruby-lang.org. Onto Ubuntu...

Jon

Jon

unread,
Feb 15, 2010, 7:01:44 PM2/15/10
to rubyin...@googlegroups.com
> > I'd like to see a solid patch as well. Are you going to write it and
> > submit a pull request?
>
> Yes, as soon as I finish some more testing. Currently the IO.popen code is working on all the mingw32 versions and the 1.8.7 and 1.9.1 mswin versions from ruby-lang.org. Onto Ubuntu...
>

IO.popen testing worked on Ubuntu Server 9.10 on 1.8.7 and 1.9.1...pull request sent to Jekyll's maintainers with this branch-of-3-mods:

http://github.com/jonforums/jekyll/tree/winfix

Jon

skim

unread,
Feb 15, 2010, 8:21:28 PM2/15/10
to RubyInstaller
Great! Look forward to their response.
Reply all
Reply to author
Forward
0 new messages