Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #1186

Re: How can I overwrite existing files with new input to running Ghostscript?.

Newsgroups comp.lang.postscript
Date 2012-12-22 19:37 -0800
References (3 earlier) <0e14a777-cf2e-4b25-bb31-2892d3e918ff@googlegroups.com> <1a56d555-9213-4d7a-a7fd-2352372e79ed@k6g2000yqf.googlegroups.com> <d4fef961-6eb2-4dac-8ffc-b89cc679297d@googlegroups.com> <a66bd6a2-8b88-4ffa-ae40-b2702b88b6e3@r13g2000vbd.googlegroups.com> <1e6eabe2-d9e0-49c0-926f-11beaab9ee0a@googlegroups.com>
Message-ID <fdfb2faa-a083-46eb-a222-e7154325419c@googlegroups.com> (permalink)
Subject Re: How can I overwrite existing files with new input to running Ghostscript?.
From Ernie Kent <ernie@erniekent.com>

Show all headers | View raw


On Saturday, December 22, 2012 12:00:36 PM UTC-5, Ernie Kent wrote:
> On Saturday, December 22, 2012 3:53:55 AM UTC-5, SaGS wrote:
> 
> > On 22 dec., 07:40, Ernie Kent <er...@erniekent.com> wrote:
> 
> > 
> 
> > > ...
> 
> > 
> 
> > > Although it overwrites the output, it doesn't actually change the file
> 
> > 
> 
> > > until GS is terminated.
> 
> > 
> 
> > > ...
> 
> > 
> 
> > > I've tried using both flushfile and closefile after showpage in your routine,
> 
> > 
> 
> > > but I can't find a way to specify the outputfile to these operators that
> 
> > 
> 
> > > doesn't give an error.
> 
> > 
> 
> > > ...
> 
> > 
> 
> > 
> 
> > 
> 
> > The output file is available after the "restore" (there where I
> 
> > 
> 
> > inserted code to print a message), the "showpage" in not sufficient.
> 
> > 
> 
> > This is what should happen, and on Windows at least this is actually
> 
> > 
> 
> > happening (I even used the Process Monitor and seen it closes the
> 
> > 
> 
> > file); I cannot try on Linux.
> 
> > 
> 
> > 
> 
> > 
> 
> > I don't know how you sync your program and GS, but in case you expect
> 
> > 
> 
> > to have the output file available when GS sends the ">>showpage, press
> 
> > 
> 
> > <return> to continue<<" message that's certainly not OK.
> 
> 
> 
> Thank you, SaGS
> 
> 
> 
> I am starting a Linux daemon to act as a GS server process. It runs GS as a background process and sends GS its stdin through a pipe. In turn the server process receives these inputs from any client process through a named fifo. 
> 
> 
> 
> Once the server daemon has started GS like this:
> 
> 
> 
>         $process = proc_open('gs -dBATCH -dNOPAUSE -sDEVICE=nullpage -', $descriptorspec, $pipes, $cwd);
> 
> 
> 
> it sends it the intialization you prescribed thus:
> 
> 
> 
>         if (is_resource($process)) {
> 
>                 //Initialize gs output device
> 
>                  fwrite($pipes[0], "/SetMyDevice {
> 
>                     [
> 
>                         /OutputFile (/home/warp/public_html/spawn/out.jpg)
> 
>                         /HWResolution [128 128]
> 
>                         /PageSize [560 72]
> 
>                         /TextAlphaBits 4
> 
>                         /GraphicsAlphaBits 4
> 
>                     /jpeg findprotodevice copydevice putdeviceprops setdevice
> 
>                 } bind def\n");
> 
>                 fflush($pipes[0]);
> 
> 
> 
> After that it enters a loop waiting for fifo inputs from clients and sending them to GS in this fashion:
> 
> 
> 
>                 //Begin while
> 
>                 while ($out != "END") {
> 
> 
> 
>                 //Here block on read from named fifo
> 
>                 $file = fopen("/tmp/fifotest","r"); //Get ready to read the input from fifo
> 
>                 $out = fread($file,"1000");             //read it
> 
>                 fclose($file);
> 
> 
> 
>                 //Tell gs to write something
> 
> 
> 
>                         fwrite($pipes[0], "
> 
>                         userdict /MyFiLeLeVeLsAvE save put
> 
>                             SetMyDevice
> 
>                                 /Times-Bold 20 selectfont
> 
>                                 3 10 moveto
> 
>                                 ($out) show
> 
>                                 showpage
> 
>                         cleardictstack clear MyFiLeLeVeLsAvE restore
> 
>                         \n");
> 
>                          fflush($pipes[0]);
> 
>                 } //End while
> 
> 
> 
> This all works in the sense that the client can send multiple Postscript files to the server and GS will write each of them successively to the same jpeg file so that if GS is terminated at any point the last postscript input sent is then the image seen in the contents of the jpeg file.
> 
> 
> 
> However, no image is actually written to the file until GS is terminated. Since the "restore" is included in the loop, I suppose this may be a Linux/Windows difference. I was trying to put a postscript "<file> flushfile" or even "<file> closefile" following the "showpage" but it seems that was incorrect and I will try it following the restore as you indicate. I was, however, unable to figure out how to specify <file> correctly in the context of the code you provided. "OutputFile" for example gave a type error. What would I use for <file> in this case?
> 
> 
> 
> Thank you again for your help; it is most appreciated.
> 
> 
> 
> Ernie

LATER: -- I think I now have a handle on what is happening.

1. If I manually start gs from the shell and enter the commands of your script, there is no write to file until after I stop gs.

2. If I enter this part of the script, 
                       userdict /MyFiLeLeVeLsAvE save put
                            SetMyDevice
                                /Hacknslash 20 selectfont
                                3 10 moveto
                                (First) show
                                showpage
                        cleardictstack clear MyFiLeLeVeLsAvE restore
(the part that was in my loop) and after that I then enter it a second time without kiling gs, gs writes output to the file TWICE. Thereafter it writes once for each time I enter that part of the script. In this case I am entering all commands directly to the gs stdin. I have no clue why it behaves this way.

3. If I operate gs via a deamon process through fifos and pipes, something similar occurs except that in this case gs writes to file only after FIVE iterations of the input script, and then each time thereafter.

This gives me a workaround klluge; just initialize it with fivr writes. I'd feel much more comfortable however if I understood why it is behaving this way.

Ernie

Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How can I overwrite existing files with new input to running Ghostscript?. Ernie Kent <ernie@erniekent.com> - 2012-12-09 10:14 -0800
  Re: How can I overwrite existing files with new input to running Ghostscript?. Helge Blischke <h.blischke@acm.org> - 2012-12-09 22:13 +0100
    Re: How can I overwrite existing files with new input to running Ghostscript?. Ernie Kent <ernie@erniekent.com> - 2012-12-09 13:52 -0800
      Re: How can I overwrite existing files with new input to running Ghostscript?. "luser.droog" <luser.droog@gmail.com> - 2012-12-09 18:28 -0600
        Re: How can I overwrite existing files with new input to running Ghostscript?. Ernie Kent <ernie@erniekent.com> - 2012-12-09 17:11 -0800
  Re: How can I overwrite existing files with new input to running Ghostscript?. SaGS <sags5495@gmail.com> - 2012-12-09 20:24 -0800
    Re: How can I overwrite existing files with new input to running Ghostscript?. Ernie Kent <ernie@erniekent.com> - 2012-12-10 07:00 -0800
      Re: How can I overwrite existing files with new input to running Ghostscript?. Ernie Kent <ernie@erniekent.com> - 2012-12-10 12:39 -0800
        Re: How can I overwrite existing files with new input to running Ghostscript?. Chris <cjl@spamcop.net> - 2012-12-11 10:12 +0000
          Re: How can I overwrite existing files with new input to running Ghostscript?. Ernie Kent <ernie@erniekent.com> - 2012-12-11 11:04 -0800
            Re: How can I overwrite existing files with new input to running Ghostscript?. Chris <cjl@spamcop.net> - 2012-12-12 07:41 +0000
              Re: How can I overwrite existing files with new input to running Ghostscript?. SaGS <sags5495@gmail.com> - 2012-12-12 03:52 -0800
                Re: How can I overwrite existing files with new input to running Ghostscript?. Chris <cjl@spamcop.net> - 2012-12-12 12:52 +0000
                Re: How can I overwrite existing files with new input to running Ghostscript?. Ernie Kent <ernie@erniekent.com> - 2012-12-12 08:45 -0800
                Re: How can I overwrite existing files with new input to running Ghostscript?. Chris <cjl@spamcop.net> - 2012-12-13 14:07 +0000
        Re: How can I overwrite existing files with new input to running Ghostscript?. SaGS <sags5495@gmail.com> - 2012-12-11 02:44 -0800
          Re: How can I overwrite existing files with new input to running Ghostscript?. Ernie Kent <ernie@erniekent.com> - 2012-12-11 11:05 -0800
          Re: How can I overwrite existing files with new input to running Ghostscript?. Ernie Kent <ernie@erniekent.com> - 2012-12-11 12:37 -0800
          Re: How can I overwrite existing files with new input to running Ghostscript?. Ernie Kent <ernie@erniekent.com> - 2012-12-21 21:40 -0800
            Re: How can I overwrite existing files with new input to running Ghostscript?. SaGS <sags5495@gmail.com> - 2012-12-22 00:53 -0800
              Re: How can I overwrite existing files with new input to running Ghostscript?. Ernie Kent <ernie@erniekent.com> - 2012-12-22 09:00 -0800
                Re: How can I overwrite existing files with new input to running Ghostscript?. Ernie Kent <ernie@erniekent.com> - 2012-12-22 19:37 -0800
                Re: How can I overwrite existing files with new input to running Ghostscript?. Chris <cjl@spamcop.net> - 2012-12-23 17:16 +0000
                Re: How can I overwrite existing files with new input to running Ghostscript?. SaGS <sags5495@gmail.com> - 2012-12-23 10:16 -0800
                Re: How can I overwrite existing files with new input to running Ghostscript?. luser- -droog <mijoryx@yahoo.com> - 2012-12-24 19:37 -0800

csiph-web