[ANN] win32_popen 0.1

Hi, all.

win32_popen is popen2,popen3,popen4 implementation on Windows adapted from
Python source code.

You can use win32_popen3 like this:

require ‘win32_popen’

fin,fout,ferr = IO.win32_popen3(“date”)
puts fout.gets
fin.print “2002-01-01\n”
while !fout.eof
puts fout.gets
end

fin,fout,ferr = IO.win32_popen3(“irb”)

begin
a = fout.getc
putc a.chr
end while a != ?>

fin.print “exit\n”

while !fout.eof
puts fout.gets
end

You can download mswin binary for your Ruby version.
http://home.nownuri.net/~phasis/popen/win32_popen_1.6.8.zip
http://home.nownuri.net/~phasis/popen/win32_popen_1.8.0.zip
Souce code and binary included.

[Requirement]

  • Ruby 1.6.5+

It may be made with other version but not verified.

[Install binary]

ruby install.rb

[Install from source]

ruby extconf.rb
nmake
ruby install.rb

[methods]

IO#win32_popen2(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout).

IO#win32_popen3(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout, child_stderr).

IO#win32_popen4(cmd[, mode]])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout_and_stderr).

Regards.

Park Heesob

Park Heesob wrote:

win32_popen is popen2,popen3,popen4 implementation on Windows adapted from
Python source code.

I prostrate myself in honor of one who has cracked that tough nut.

Question: Why are pipes so >fucking< hard???

···


Phlip
I gotta have my orange juice. | Jesu, Juva
– Whip me. Beat me. Make me install Oracle. –

Park Heesob wrote:

win32_popen is popen2,popen3,popen4 implementation on Windows adapted from
Python source code.

Wow, what a great late Christmas present!

Thanks very much.

Bless you…seriously!

This will be integrated into FreeRIDE before 2003 :wink:

-rich

···

On Tuesday, December 31, 2002, at 02:01 AM, Park Heesob wrote:

Hi, all.

win32_popen is popen2,popen3,popen4 implementation on Windows adapted
from
Python source code.

You can use win32_popen3 like this:

require ‘win32_popen’

fin,fout,ferr = IO.win32_popen3(“date”)
puts fout.gets
fin.print “2002-01-01\n”
while !fout.eof
puts fout.gets
end

fin,fout,ferr = IO.win32_popen3(“irb”)

begin
a = fout.getc
putc a.chr
end while a != ?>

fin.print “exit\n”

while !fout.eof
puts fout.gets
end

You can download mswin binary for your Ruby version.
http://home.nownuri.net/~phasis/popen/win32_popen_1.6.8.zip
http://home.nownuri.net/~phasis/popen/win32_popen_1.8.0.zip
Souce code and binary included.

[Requirement]

  • Ruby 1.6.5+

It may be made with other version but not verified.

[Install binary]

ruby install.rb

[Install from source]

ruby extconf.rb
nmake
ruby install.rb

[methods]

IO#win32_popen2(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout).

IO#win32_popen3(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout, child_stderr).

IO#win32_popen4(cmd[, mode]])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout_and_stderr).

Regards.

Park Heesob

quick question on this library…how would one interrupt a running
(popen’ed) process if it got hung up, etc?

-rich

···

On Tuesday, December 31, 2002, at 02:01 AM, Park Heesob wrote:

Hi, all.

win32_popen is popen2,popen3,popen4 implementation on Windows adapted
from
Python source code.

You can use win32_popen3 like this:

require ‘win32_popen’

fin,fout,ferr = IO.win32_popen3(“date”)
puts fout.gets
fin.print “2002-01-01\n”
while !fout.eof
puts fout.gets
end

fin,fout,ferr = IO.win32_popen3(“irb”)

begin
a = fout.getc
putc a.chr
end while a != ?>

fin.print “exit\n”

while !fout.eof
puts fout.gets
end

You can download mswin binary for your Ruby version.
http://home.nownuri.net/~phasis/popen/win32_popen_1.6.8.zip
http://home.nownuri.net/~phasis/popen/win32_popen_1.8.0.zip
Souce code and binary included.

[Requirement]

  • Ruby 1.6.5+

It may be made with other version but not verified.

[Install binary]

ruby install.rb

[Install from source]

ruby extconf.rb
nmake
ruby install.rb

[methods]

IO#win32_popen2(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout).

IO#win32_popen3(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout, child_stderr).

IO#win32_popen4(cmd[, mode]])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout_and_stderr).

Regards.

Park Heesob

Park,

Thanks a lot for this package.

Unfortunately, when I compile it on my Windows XP Pro using VC++ 6.0 and run
it with
ruby 1.7.3 (2002-11-17) [i386-mswin32] it hangs after doing this:

···

C:\test>ruby test.rb

test1
The current date is: Tue 12/31/2002
Enter the new date: (mm-dd-yy) 2002-01-01
The system cannot accept the date entered.


Please help.
Thanks and have a Very Happy New Year !

– shanko

“Park Heesob” phasis@kornet.net wrote in message
news:auremp$s0b$1@news.hananet.net

Hi, all.

win32_popen is popen2,popen3,popen4 implementation on Windows adapted from
Python source code.

You can use win32_popen3 like this:

require ‘win32_popen’

fin,fout,ferr = IO.win32_popen3(“date”)
puts fout.gets
fin.print “2002-01-01\n”
while !fout.eof
puts fout.gets
end

fin,fout,ferr = IO.win32_popen3(“irb”)

begin
a = fout.getc
putc a.chr
end while a != ?>

fin.print “exit\n”

while !fout.eof
puts fout.gets
end

You can download mswin binary for your Ruby version.
http://home.nownuri.net/~phasis/popen/win32_popen_1.6.8.zip
http://home.nownuri.net/~phasis/popen/win32_popen_1.8.0.zip
Souce code and binary included.

[Requirement]

  • Ruby 1.6.5+

It may be made with other version but not verified.

[Install binary]

ruby install.rb

[Install from source]

ruby extconf.rb
nmake
ruby install.rb

[methods]

IO#win32_popen2(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout).

IO#win32_popen3(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout, child_stderr).

IO#win32_popen4(cmd[, mode]])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout_and_stderr).

Regards.

Park Heesob

Hi,
I added win32_kill method to kill piped process, because
Process.kill(“KILL”,pid) is failed on Ruby 1.6.8.

IO#win32_kill(pid)
Terminate the specified process id.

You can kill piped process like this:

fin,fout,ferr = IO.win32_popen3(“date”)
IO.win32_kill(fin.pid) # fin.pid, fout.pid, ferr.pid → pid of piped
process

Process.kill(“KILL”,fin.pid) also available on Ruby v1.8.0

Regards.

Park Heesob

“Park Heesob” phasis@kornet.net wrote in message
news:auremp$s0b$1@news.hananet.net

···

win32_popen is popen2,popen3,popen4 implementation on Windows adapted from
Python source code.

You can download mswin binary for your Ruby version.
http://home.nownuri.net/~phasis/popen/win32_popen_1.6.8.zip
http://home.nownuri.net/~phasis/popen/win32_popen_1.8.0.zip
Souce code and binary included.

[Requirement]

  • Ruby 1.6.5+

It may be made with other version but not verified.

[Install binary]

ruby install.rb

[Install from source]

ruby extconf.rb
nmake
ruby install.rb

[methods]

IO#win32_popen2(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout).

IO#win32_popen3(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout, child_stderr).

IO#win32_popen4(cmd[, mode]])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout_and_stderr).

Wonderful!

martin

···

Park Heesob phasis@kornet.net wrote:

Hi, all.

win32_popen is popen2,popen3,popen4 implementation on Windows adapted from
Python source code.

Thanks so much for developing this. I can put it to good use right now.
I’ve done some experimenting with your code.
I’m using ruby 1.66, so, some of what I’ve found may be due to that.

  1. When using win32_popen3 to pipe a ruby script you must use the command
    (“ruby.exe scriptname”) in order for both fin and fout to work properly.
    If you use the command(“scriptname”) the child script will run but fin
    doesn’t work properly. You get the following error in the child script
    Bad file descriptor (Errno::EBADF)

  2. When using Marshal to pipe an object to a script the following doesn’t
    work (Marshal barks at it)
    Marshal.dump(some_object, fin)

    However, you can overcome this by
    data=Marshal.dump(some_object)
    fin.print data

    on the client side you can retrieve the object
    some_obj=Marshal.load($stdin)

Thanks again for a slick piece of work.

Ernie
“Park Heesob” phasis@kornet.net wrote in message
news:auremp$s0b$1@news.hananet.net

···

Hi, all.

win32_popen is popen2,popen3,popen4 implementation on Windows adapted from
Python source code.

Regards.

Park Heesob

Though I don’t use Windows much anymore, this is good stuff.

This should be included in the standard Ruby distribution for
Windows at some point.

Phil

In article auremp$s0b$1@news.hananet.net,

···

Park Heesob phasis@kornet.net wrote:

Hi, all.

win32_popen is popen2,popen3,popen4 implementation on Windows adapted from
Python source code.

You can use win32_popen3 like this:

require ‘win32_popen’

fin,fout,ferr = IO.win32_popen3(“date”)
puts fout.gets
fin.print “2002-01-01\n”
while !fout.eof
puts fout.gets
end

fin,fout,ferr = IO.win32_popen3(“irb”)

begin
a = fout.getc
putc a.chr
end while a != ?>

fin.print “exit\n”

while !fout.eof
puts fout.gets
end

You can download mswin binary for your Ruby version.
http://home.nownuri.net/~phasis/popen/win32_popen_1.6.8.zip
http://home.nownuri.net/~phasis/popen/win32_popen_1.8.0.zip
Souce code and binary included.

[Requirement]

  • Ruby 1.6.5+

It may be made with other version but not verified.

[Install binary]

ruby install.rb

[Install from source]

ruby extconf.rb
nmake
ruby install.rb

[methods]

IO#win32_popen2(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout).

IO#win32_popen3(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout, child_stderr).

IO#win32_popen4(cmd[, mode]])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout_and_stderr).

Regards.

Park Heesob


“Or perhaps the truth is less interesting than the facts?”
Amy Weiss (accusing theregister.co.uk of engaging in ‘tabloid journalism’)
Senior VP, Communications
Recording Industry Association of America

“Ernie” erne@powernav.com wrote in message

However, you can overcome this by
    data=Marshal.dump(some_object)
    fin.print data

  on the client side you can retrieve the object
  some_obj=Marshal.load($stdin)

Just curious … what client side ?
Are you trying some kind of distributed ruby ?
If yes, have you looked at drb on RAA ?

Would be interested in looking at your code.
Thanks,

– shanko

Sorry for the late reply. I am catching up on missed emails.
The date format is incorrect. Asking for MM-dd-yy, it was sent yyyy-mm-dd.
I think you should just change the test:
fin.print “2002-01-01\n” to fin.print “01-01-02\n”

I prefer “01-13-02\n”, since it avoids the mm/dd confusion.

-matt

···

-----Original Message-----
From: Shashank Date [mailto:sdate@kc.rr.com]
Sent: Tuesday, December 31, 2002 8:24 PM
To: ruby-talk ML
Subject: Re: [ANN] win32_popen 0.1

Park,

Thanks a lot for this package.

Unfortunately, when I compile it on my Windows XP Pro using VC++ 6.0 and run
it with
ruby 1.7.3 (2002-11-17) [i386-mswin32] it hangs after doing this:

C:\test>ruby test.rb

test1
The current date is: Tue 12/31/2002
Enter the new date: (mm-dd-yy) 2002-01-01
The system cannot accept the date entered.


Please help.
Thanks and have a Very Happy New Year !

– shanko

“Park Heesob” phasis@kornet.net wrote in message
news:auremp$s0b$1@news.hananet.net

Hi, all.

win32_popen is popen2,popen3,popen4 implementation on Windows adapted from
Python source code.

You can use win32_popen3 like this:

require ‘win32_popen’

fin,fout,ferr = IO.win32_popen3(“date”)
puts fout.gets
fin.print “2002-01-01\n”
while !fout.eof
puts fout.gets
end

fin,fout,ferr = IO.win32_popen3(“irb”)

begin
a = fout.getc
putc a.chr
end while a != ?>

fin.print “exit\n”

while !fout.eof
puts fout.gets
end

You can download mswin binary for your Ruby version.
http://home.nownuri.net/~phasis/popen/win32_popen_1.6.8.zip
http://home.nownuri.net/~phasis/popen/win32_popen_1.8.0.zip
Souce code and binary included.

[Requirement]

  • Ruby 1.6.5+

It may be made with other version but not verified.

[Install binary]

ruby install.rb

[Install from source]

ruby extconf.rb
nmake
ruby install.rb

[methods]

IO#win32_popen2(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout).

IO#win32_popen3(cmd[, mode])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout, child_stderr).

IO#win32_popen4(cmd[, mode]])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout_and_stderr).

Regards.

Park Heesob

I called the child process the client side (my mistake). Its the process
started with win32_popen. Nothing special about it. I just wanted to see
if I could load an object using it.
I’m running windows XP pro and Ruby 1.66.
I use drb in some of my applications. What’s nice about this code is that
you can start a process feed it some data and then terminate the calling
program without having to wait for the piped process to complete. For
example, a cgi program that sends an email to the client. With threads or
in the cgi code itself, the call to the mail server takes some time to
complete. With popen, you can start a process to send the email. Finish
writing the cgi output then exit the cgi program. The user gets the html
response faster. You could use a drb object to do the same, but any method
call on that object would have to complete before exiting the cgi program.
Spawning a thread also requires waiting.

Ernie
“Shashank Date” sdate@kc.rr.com wrote in message
news:9JKQ9.67172$Zt4.781743@twister.rdc-kc.rr.com

···

“Ernie” erne@powernav.com wrote in message

However, you can overcome this by
    data=Marshal.dump(some_object)
    fin.print data

  on the client side you can retrieve the object
  some_obj=Marshal.load($stdin)

Just curious … what client side ?
Are you trying some kind of distributed ruby ?
If yes, have you looked at drb on RAA ?

Would be interested in looking at your code.
Thanks,

– shanko

Surely YYYY-MM-DD is the only intelligent date format. No confusion
whatsoever. Since the Y2K fiasco, I’ve never seen any advantage in
abbreviating the year, even in informal writing.

Gavin

···

On Thursday, January 23, 2003, 6:08:42 AM, Matt wrote:

Sorry for the late reply. I am catching up on missed emails.
The date format is incorrect. Asking for MM-dd-yy, it was sent yyyy-mm-dd.
I think you should just change the test:
fin.print “2002-01-01\n” to fin.print “01-01-02\n”

I prefer “01-13-02\n”, since it avoids the mm/dd confusion.

Surely YYYY-MM-DD is the only intelligent date format. No confusion
whatsoever. Since the Y2K fiasco, I’ve never seen any advantage in
abbreviating the year, even in informal writing.

Agreed, I always use YYYY-MM-DD now and will always write the year out
as YYYY on both formal & informal documents.

I’m working on the principle that if enough of us do it there won’t be a
problem again in 97 years.

Rob