Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gs out of wish

6 views
Skip to first unread message

Wolf Grossi

unread,
Jan 26, 2003, 7:15:04 AM1/26/03
to
Hi tcl'ers,

on Linux I have a wish-script which calls ghostscript using
<exec /bin/sh "gs -sPAPERSIZE=a4 -r60 -q -dBATCH file.ps>
to have a preview of a postscript file.

Works fine, but ghostscripts grabs the focus and does not allow my
wish-script to get the focus and to execute an ok-button.

What i want to accpomplish is a preview of a ps-file and then let the
wish-user to continue, that means ending gs by pushing the ok-button.

Any hints would be very much appreciated, tnx for reading
Wolf

Derk Gwen

unread,
Jan 26, 2003, 10:17:16 AM1/26/03
to
Wolf Grossi <Go2de...@magro-soft.com> wrote:
# Hi tcl'ers,
#
# on Linux I have a wish-script which calls ghostscript using
# <exec /bin/sh "gs -sPAPERSIZE=a4 -r60 -q -dBATCH file.ps>
# to have a preview of a postscript file.
#
# Works fine, but ghostscripts grabs the focus and does not allow my
# wish-script to get the focus and to execute an ok-button.
#
# What i want to accpomplish is a preview of a ps-file and then let the
# wish-user to continue, that means ending gs by pushing the ok-button.

I don't know exactly what ghostscript is doing, but in general Tcl does one
command at a time, and doesn't allow any other command, such as responding
to keyboard or mouse events, to interrupt it. Unless that command specifically
checks for new events the way vwait does.

That means once the exec command starts, it runs exclusively until the
executed command returns.

If you have a long running command and wish to keep wish responsive, the usual
technique is to open a pipeline file as nonblocking, and read from that
as it produces output. Instead of
set ::rc [catch {set ::output [exec command a b c d]} ::rs]
more like
set ::pipe [open |[list command a b c d] r]
fconfigure $::pipe -blocking 0
set ::output ""
set ::rc 0
fileevent readable $::pipe "
append ::output \[read $::pipe\]
if {\[eof $::pipe\]} {
fconfigure $::pipe -blocking 1
set ::rc \[catch {close $::pipe} ::rs\]
}
"
vwait ::rc

And rather than just accumulate pipe output until its completion,
you can also display it immediately in something like a text widget
or progress/status bar.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
Haven't you ever heard the customer is always right?

Wolf Grossi

unread,
Jan 26, 2003, 11:19:21 AM1/26/03
to
Derk Gwen wrote:
[snip]

> If you have a long running command and wish to keep wish responsive, the usual
> technique is to open a pipeline file as nonblocking, and read from that
[snip]
That's it!
Thanks a lot
Wolf

Neil Madden

unread,
Jan 26, 2003, 3:32:05 PM1/26/03
to

Do you care about the output from gs? If not, then you can just do:

exec gs -sPAPERSIZE=a4 -r60 -q -dBATCH file.ps &

The "&" on the end causes it to work in the background, so Tcl can get
on with other stuff (like responding to button clicks). Also, note that
you generally don't need to execute /bin/sh, but just the program
directly. If you need the full path to the executable, you can use
[auto_execok] to get it.

Neil.

Wolf Grossi

unread,
Jan 27, 2003, 3:38:07 AM1/27/03
to
Neil Madden wrote:
> Wolf Grossi wrote:
>
>> Hi tcl'ers,
>>
>> on Linux I have a wish-script which calls ghostscript using
>> <exec /bin/sh "gs -sPAPERSIZE=a4 -r60 -q -dBATCH file.ps>
>> to have a preview of a postscript file.
>>
>> Works fine, but ghostscripts grabs the focus and does not allow my
>> wish-script to get the focus and to execute an ok-button.
>>
>> What i want to accpomplish is a preview of a ps-file and then let the
>> wish-user to continue, that means ending gs by pushing the ok-button.
>>
>> Any hints would be very much appreciated, tnx for reading
>> Wolf
>>
>
> Do you care about the output from gs? If not, then you can just do:
>
> exec gs -sPAPERSIZE=a4 -r60 -q -dBATCH file.ps &

This was my first attempt but it does not show the output, and i wanna
see it :-)
I do piping as Derk Gwen suggested and it does exactly what I want.
Thanks
Wolf

Donald Arseneau

unread,
Jan 27, 2003, 7:10:44 AM1/27/03
to
Wolf Grossi <Go2de...@magro-soft.com> writes:

> on Linux I have a wish-script which calls ghostscript using
> <exec /bin/sh "gs -sPAPERSIZE=a4 -r60 -q -dBATCH file.ps>
> to have a preview of a postscript file.
>
> Works fine, but ghostscripts grabs the focus and does not allow my
> wish-script to get the focus and to execute an ok-button.

I suggest using blt and the blt::bgexec command.

Nevertheless, you can exec in the background using a "pipe" open.

Donald Arseneau as...@triumf.ca

lvi...@yahoo.com

unread,
Jan 27, 2003, 7:32:20 AM1/27/03
to

According to Wolf Grossi <Go2de...@magro-soft.com>:
:on Linux I have a wish-script which calls ghostscript using

:<exec /bin/sh "gs -sPAPERSIZE=a4 -r60 -q -dBATCH file.ps>
:to have a preview of a postscript file.
:
:Works fine, but ghostscripts grabs the focus and does not allow my
:wish-script to get the focus and to execute an ok-button.

Why not say

exec /bin/sh -c "gs -sPAPERSIZE=a4 -r60 -q -dBATCH file.ps" &

and just put the command into the background?
--
Tcl - The glue of a new generation. <URL: http://wiki.tcl.tk/ >
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
<URL: mailto:lvi...@yahoo.com > <URL: http://www.purl.org/NET/lvirden/ >

Neil Madden

unread,
Jan 27, 2003, 12:39:52 PM1/27/03
to

Do you want it on standard output, or do you want it available to your
script? If you just want the output to turn up on stdout, then you can use:

exec >&@stdout gs -sPAPERSIZE=a4 -r60 -q -dBATCH file.ps &

Otherwise the fileevent/piping alternative is the way to go.

Neil.

Jean-Luc Fontaine

unread,
Jan 28, 2003, 6:47:59 AM1/28/03
to
Wolf Grossi <Go2de...@magro-soft.com> wrote in message news:<3e33d155$1...@e-post.inode.at>...

Take a look at print.tcl in the moodss tarball
(http://jfontain.free.fr/moodss), where gs is used as a print
previewer: it might give you some ideas.

Jean-Luc

Wolf Grossi

unread,
Feb 1, 2003, 12:13:55 PM2/1/03
to
Thank you all for the very helpful tips;
Wolf

0 new messages