Re: gsapi_set_stdio() and -OutputFile=-

Ken Sharp <[email protected]>
Newsgroups gmane.comp.printing.ghostscript.devel
Message-ID <[email protected]>
At 15:30 25/03/2016 +0100, Hartmut Goebel wrote:

>The output-device I'm using is bmp16.
>
>If passing -OutputFile=-, the image data is written to the stdout
>instead of being passed to the stdout-function I've set with
>gsapi_set_stdio().

This has already been answered recently on gs-devel, also see this bug report:

http://bugs.ghostscript.com/show_bug.cgi?id=694993


My own take on this is that there is a difference between the system (OS) 
stdout and the *PostScript* stdout. gsapi_set_stdio alters the PostScript 
stdin and stdout to be the ones you define, it does not affect the system 
stdout.

So if you set the OutputFile to '-' then it sends the device output to the 
*system* stdout. Altering the PostScript stdout has no effect on this.

As one of my colleagues has also stated this is not entirely clear, and it 
may be something we would like to change. However because of architectural 
constraints (see the bug report above), we cannot currently do so as we 
would need to change the device API in Ghostscript, which would 
(potentially at least) be a breaking change for all Ghostscript devices.

While we can alter all the devices we support, there are commercial users 
of Ghostscript with their own devices that we would have to help through 
the transition, and there are known to be 'free user' devices which have 
not (for good reasons) been contributed to Ghostscript, and would also have 
to be updated, and these are completely out of our control.

We are already considering a breaking change to the device API for a future 
release, and we *may* choose to incorporate an architectural change which 
would allow us to redirect OutputFile to PostScript stdout instead of 
system stdout and would allow you to do what you want.

However, I would counsel caution on this approach anyway. PostScript is a 
programming language, and any given PostScript program is at liberty to 
write anything it likes to the PostScript stdout, potentially this means 
that Ghostscript messages, PostScript program messages, and errors would be 
written to 'stdout' along with your device's data. Clearly this would badly 
corrupt the data stream!

My own advice would be to find some other means of achieving your goal, 
have you considered writing to a pipe instead of stdout ? Or writing your 
own device and having it deliver data in some fashion suitable for your use.


Finally, you must provide an output filename for the devices that output to 
a file.


                     Ken

PS A PostScript program which writes 'Hello World to stdout

8<------------------------------------8<---------------------------8<

%!
(Hello World) == flush
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.