INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Problem reading from command pipelined channel

Problem reading from command pipelined channel

(OP)
Hello,

I'm trying to read from a command pipelined channel but the channel closes before I've read the wanted output. I'm trying to read the boundingbox parameters (see below) but the channel closes at the very same line, before the line is properly read.

The wanted data could be extracted by using the exceptional return but I'm curious as to why this behavior appears and what could be a proper way to perform this read.

Any ideas and/or comments are much appreciated.

Here is the code I'm running:

CODE

set cmd "|\"C:/Program Files/gs/gs9.05/bin/gswin64c.exe\" -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox \"C:/Program Files (x86)/term/outTest.pdf\""

set f [open $cmd "r"]

while {true} {
	if {[gets $f line] < 0} {
		if {[catch {close $f} msg]} {
			puts "Channel closed (<0):\n$msg"
		}
		break
	} elseif {[eof $f]} {
		if {[catch {close $f} msg]} {
			puts "Channel closed (EOF):\n$msg"
		}
		break
	} else {
		puts $line
	}
} 
Output:

CODE

GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Channel closed (<0):
%%BoundingBox: 0 336 596 756
%%HiResBoundingBox: 0.090000 336.563990 595.007982 755.909977 

Here is the output when the GS script is run in the command promt:

CODE --> output

C:\Users\Me>"C:\Program Files\gs\gs9.05\bin\gswin64c.exe" -dSAFER -dNOPAUSE -dBA
TCH -sDEVICE=bbox "C:\Program Files (x86)\term\outTest.pdf"
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
%%BoundingBox: 0 336 596 756
%%HiResBoundingBox: 0.090000 336.563990 595.007982 755.909977

C:\Users\Me> 

Thanks

Peter

RE: Problem reading from command pipelined channel

Are you sure it's the pipeline that's misbehaving and not Ghostscript? I don't know how the arguments work for GS so I would try a simpler pipeline and work up from there. Also, "while true" is going to go berserk if you ever get stuck in "else".

_________________
Bob Rashkin

RE: Problem reading from command pipelined channel

(OP)
Thanks for the reply,

Hmm, it seems like GS is returning a '-1' right after the line stating "Page 1" causing the pipeline to close.

Otherwise I believe the GS arguments to be ok. And I hear you regarding while{true}-loop. It's not pretty and was merely used for debugging. It will be adjusted as soon as this start to work smile.

If I'm not mistaking, the pipeline automatically closes when a '-1' is read (please correct me if I'm wrong).

So if my thesis is correct and a -1 is returned after "Page 1" causing the pipeline to automatically close: Is there a way to get tcl to disregard the first '-1' and keep on reading until the second '-1'?

RE: Problem reading from command pipelined channel

I know nothing of GS. As I suggested above, I'd work out the kinks in the process pipeline with something simpler. Also, a lot of these OS-type deals in Tcl were really designed for Unix and I don't trust that they always work well in Windows (just my own paranoia).

Anyway, you're telling it to close if it reads <0 so you could just as well put in a counter and complicate your condition:

CODE -->

if {[gets $f line] < 0 && $counter>1} 

That said, I think GS sending -1 is ominous, but I don't know anything about GS as I said.

_________________
Bob Rashkin

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close