Autore Topic: Problema di un PDF vuoto - forse Cairo troppo lento ?  (Letto 588 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.725
  • Ne mors quidem nos iunget
    • Mostra profilo
Problema di un PDF vuoto - forse Cairo troppo lento ?
« il: 17 Agosto 2013, 17:05:44 »
Vi riporto questa discussione apparsa nella M.L.I.:


" I have been trying around this problem and found a reproduceable behaviour.

To make it short, this is the standard way in my program:

Within SUB Main, I read the mails from the server (contact forms), one
by one. Each one's data is processed into a pdf (pdf made by Cairo
class) and a mail text body, then sent to the recipient by e-mail via
the external script (shelling out).

When the whole thing runs from cron, it will deliver 0 Byte PDFs, but
the originals on the system are fine (the copies remain in the
directory). The mailing system does not see any error.

Now is the trick: When I use a ready-made pdf copy and call mail-sending
SUB with these data directly, it will deliver the PDF correctly. This is reproduceable.

So my thought was, it might be that when started from cron, the Gambas
app runs through so fast that it calls mail sending BEFORE Cairo is
ready writing the PDF. This would mean Cairo is working on its own. So
there is a file (you have to give the file name before starting to
print), but 0 bytes, and that is sent. Only after sending the mail, the
rest of the data is written and remains in the directory.

How could I check for Cairo to be done with the file before sending the
mail? Or should I just wait couple of seconds?

Rolf
"


" AFAIK, Cairo is synchronous, so when Cairo.End() returns, your PDF file
should be complete. Show us some code...

--
Benoît Minisini
"


" Problems with cron usually result from missing pathes. Cron does not
starts a shell with its enviroment. So you have to use absolut paths to
your programm(s) and perhap setup environment variable if needed.

Hope thät helps
Rolf
"
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.725
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Problema di un PDF vuoto - forse Cairo troppo lento ?
« Risposta #1 il: 19 Agosto 2013, 15:28:29 »
...continua...


" At first, I thought this might solve it, but it's some problem within
the external Perl script when called from a shell within a cron
environment. It seems to have to do with paths, but it's beyond my
reach, maybe a call to a Perl library.

In the end, I solved this by starting the mail transfer not from a shell
within the Gambas program but afterwards. The sendEmail Perl script then
runs on its own, called by a bash script, and reads the data from a list
the Gambas program has prepared beforehand.

Calling myProgram.Gambas && myMailScript runs flawlessly.

It's just a shame I didn't get the Gambas SMTP client to work, it would
have made things a lot easier.

Regards
Rolf
"
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »