I have a procedure which is writing a file, emailing it using mail_files
, and then an OS-DELETE
statement to delete the file after it is sent. The call to the external procedure which calls mail_files
or the actual OS-COMMAND
itself are asynchronous. The OS is AIX 6 and the version of Progress is 102B. Here's an example below:
Here is the main procedure:
DEFINE STREAM outStr.
OUTPUT STREAM outStr TO foo.txt.
FOR EACH customer NO-LOCK:
EXPORT STREAM outStr customer.
END.
OUTPUT STREAM outStr CLOSE. /*EDIT: The problem occurs even if it's closed*/
RUN sendmail.p.
OS-DELETE foo.txt.
Here is sendmail.p:
DEFINE STREAM stMail.
OUTPUT STREAM stMail THROUGH
"mail_files -f foo@bar.com -t me@here.com -s\"subject\" -b~\foo.txt\").
PUT STREAM stMail "Email body".
OUTPUT STREAM stMail CLOSE.
In testing it on my own, I can't replicate the error. Is Progress trying to "optimize" something here? Is there anything to cleanly make it do what I want without hard-coding a pause?
EDIT:
The stream is being closed before the email attempt, but the error still occurs. No partial file is sent.
The error I get is from mail_files
because it can't find the file. I've checked, and no other processes are scheduled to run which would access the file.
No such file or directory
/usr/local/bin/mail_files[268]: foo.txt: cannot open
DEFINE STREAM outStr.
OUTPUT STREAM outStr TO foo.txt.
FOR EACH customer NO-LOCK:
EXPORT STREAM outStr customer.
END.
/* Dont forget to close */
OUTPUT STREAM outStr CLOSE.
RUN sendmail.p.
OS-DELETE foo.txt.
This looks like a pathing issue to me.
In your output stream statement you never define the path that the file will be written to. This will result in the path being the current working directory of whatever application this is running under. The path of the current working directory may not necessarily be the same path that mail__files is reading from (which appears to be /usr/local/bin).
I would suggest updating your code as follows:
OUTPUT STREAM outStr TO /usr/tmp/foo.txt.
and
OUTPUT STREAM stMail THROUGH
"mail_files -f foo@bar.com -t me@here.com -s\"subject\" -b\"/usr/tmp/foo.txt\").
...or you could just try updating this line to point at /usr/local/bin (although /usr/local/bin doesn't really strike me as an appropriate directory for temporary files):
OUTPUT STREAM outStr TO /usr/local/bin/foo.txt.
If I understood correctly, Progress removes your file before mail_files use it.
If this is that, you can use unique files and cron, delete all files that are supperior to a certain date.
For example:
DEFINE VARIABLE wlc-Identifiant AS CHARACTER NO-UNDO.
DEFINE VARIABLE wlc-file-txt AS CHARACTER NO-UNDO.
wlc-Identifiant = STRING(YEAR(TODAY), "9999") + STRING(MONTH(TODAY), "99") + STRING(DAY(TODAY), "99") + REPLACE(STRING(TIME, "HH:MM:SS"), ":", "").
wlc-file-txt = wlc-Identifiant + "foo.txt".
DEFINE STREAM outStr.
OUTPUT STREAM outStr TO VALUE (wlc-file-txt).
FOR EACH customer NO-LOCK:
EXPORT STREAM outStr customer.
END.
OUTPUT STREAM outStr CLOSE.
RUN sendmail.p (INPUT wlc-file-txt). /* add the file in parameter */
/*OS-DELETE foo.txt.*/ /* It 's a cron job */
In sendmail.p:
DEFINE INPUT PARAMETER wlpic-file-txt AS CHARACTER NO-UNDO.
DEFINE STREAM stMail.
OUTPUT STREAM stMail THROUGH
"mail_files -f foo@bar.com -t me@here.com -s\"subject\" -b~\" + wlpic-file-txt + "\").
PUT STREAM stMail "Email body".
OUTPUT STREAM stMail CLOSE.
And with cron, delete old files that were created there today - 1 (it's an examle)
I hope it will help you. :)