Re: Problem with stdout

Ken Sharp <[email protected]> Wed, 28 Mar 2018 16:40:59 +0100
Newsgroups gmane.comp.printing.ghostscript.devel
Message-ID <[email protected]>
At 10:30 28/03/2018 +0000, Kevin Schmitz wrote:


>I am writing an application in C++(Visual Studio 2017) for Windows 10 with 
>Ghostscript *.23 and I am not able to write an output in stdout.
>
>
>
>But if I choose""-sOutputFile=myfile.jpeg" instead of 
>"-sOutputFile=%stdout", then everything works fine. I also used the 
>following variants:

The first thing to be aware of is that when we say the device's output is 
piped to stdout, that's *exactly* what we mean. It is not sent to any 
'redirected' stdout, its sent directly to the underlying OS stdout.

The redirection of stdout and stderr to callback functions only applies to 
what Ghostscript would ordinarily send to stdout or stderr. When you 
specify "-o -" to Ghostscript it sends the device output directly to stdout.


So the basic problem is that you are not creating a console application, 
you are creating a 'window' application. The reason that's a problem is 
because when the application is run as a window, there is no stdout. This 
causes the attempt to set the file handle to binary to fail, which trickles 
back up through the code and throws an error.

You can get the same result by running the two Ghostscript executables; the 
Windowed executable will throw an error and the console executable will 
beep annoyingly at you as it sends the output to stdout:

gswin32 -sDEVICE=jpeggray -o - /ghostpdl/examples/golfer.eps

gswin32c -sDEVICE=jpeggray -o - /ghostpdl/examples/golfer.eps


If you want to write the device output to stdout then you need to create a 
console application. I'm not a C++ or C# programmer so I can't really help 
you there, but Visual Studio will (in earlier versions at least!) give you 
the option to create a new project as a 'Console Application'.

There is currently no simple way to return the output of the standard 
devices in memory. You can get the raw bitmap back in memory by working 
from the display device, but that does not apply JPEG compression.


To help you any further we'd need to know what you are trying to achieve 
with this.



                     Regards,


                         Ken Sharp