Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   using pipe, but subprocess didn't flush. (http://www.velocityreviews.com/forums/t857023-using-pipe-but-subprocess-didnt-flush.html)

kim jun young 04-19-2009 07:48 AM

using pipe, but subprocess didn't flush.
 
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?


Robert Klemme 04-19-2009 04:16 PM

Re: using pipe, but subprocess didn't flush.
 
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


All times are GMT. The time now is 04:21 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57