Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > using pipe, but subprocess didn't flush.

Reply
Thread Tools

using pipe, but subprocess didn't flush.

 
 
kim jun young
Guest
Posts: n/a
 
      04-19-2009
hi, all,

I wanna to execute subprocess and catch subprocess' output from a pipe
in a parent process.

but, unfortunately, a subprocess didn't flush it's output in stdout.
As a result, the parent process cannot recognize what the subprocess
did.

this is a sample code for my case.

clue 1) when I executed "isql -Usybase -P -SHOME_SERVER"

the first prompt of it is

1>

clue 2) in my program, I executed this.
read = IO.popen("isql -Usybase -P -SHOME_SERVER", "r")

puts read.sysread(2)

read.close

also it printout "1>"

clue 3) different case of clue 2
read = IO.popen("isql -Usybase -P -SHOME_SERVER", "r+") # read-write
mode

puts read.sysread(2)

read.close

it doesn't print out anything.

clue 4) different case of clue 2
require "open3"
include Open3

stdin, stdout, stderr = popen3("isql -Usybase -P -SHOME_SERVER")

puts stdout.sysread(1) <-- wait forever.

could you suggest me solution?

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      04-19-2009
On 19.04.2009 09:48, kim jun young wrote:
> hi, all,
>
> I wanna to execute subprocess and catch subprocess' output from a pipe
> in a parent process.
>
> but, unfortunately, a subprocess didn't flush it's output in stdout.
> As a result, the parent process cannot recognize what the subprocess
> did.
>
> this is a sample code for my case.
>
> clue 1) when I executed "isql -Usybase -P -SHOME_SERVER"
>
> the first prompt of it is
>
> 1>
>
> clue 2) in my program, I executed this.
> read = IO.popen("isql -Usybase -P -SHOME_SERVER", "r")
>
> puts read.sysread(2)


Why are you using #sysread?

> read.close
>
> also it printout "1>"


This is most likely because stdin of the child is closed which makes
"isql" terminate and hence flush its IO buffers.

> clue 3) different case of clue 2
> read = IO.popen("isql -Usybase -P -SHOME_SERVER", "r+") # read-write
> mode
>
> puts read.sysread(2)
>
> read.close
>
> it doesn't print out anything.
>
> clue 4) different case of clue 2
> require "open3"
> include Open3
>
> stdin, stdout, stderr = popen3("isql -Usybase -P -SHOME_SERVER")
>
> puts stdout.sysread(1) <-- wait forever.
>
> could you suggest me solution?


You have no control over how the child process does its IO. If it
chooses to do IO buffering you cannot switch if off externally unless
the program provides a mechanism to do so.

I believe there is a library for setting up pseudo terminals in Ruby
programs which might work if "isql" uses that information to decide
whether to sync IO or not. If that does not work, you're probably out
of luck.

IMHO you better try to access MS SQL Server or Sybase (whichever you
use) via DBD / DBI if possible at all.

Kind regards

robert
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
subprocess.check_call() fails ... but only on my production machine Chris Curvey Python 2 10-13-2010 08:27 AM
how to import subprocess into my 'subprocess.py' file hiral Python 2 05-05-2010 12:56 PM
subprocess wait() waits forever, but os.system returns grayaii Python 4 05-07-2008 09:31 PM
subprocess.Popen fails, but os.system works bahoo Python 1 04-25-2007 05:21 AM
[Subprocess/Windows] subprocess module under Windows 98 Andreas Jung Python 2 11-02-2005 05:41 PM



Advertisments