我有一个过程,它正在写一个文件,使用mail_files
发送电子邮件,然后使用OS-DELETE
语句在发送后删除文件。调用mail_files
的外部过程或实际的OS-COMMAND
本身是异步的。操作系统为AIX 6, Progress版本为102B。下面是一个例子:
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.
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.
在我自己的测试中,我不能重复错误。Progress是否在尝试"优化"某些内容?有没有什么东西可以让它干净利落地做我想要的,而不需要硬编码暂停?
编辑:在尝试发送电子邮件之前,流已被关闭,但错误仍然发生。没有发送部分文件。
我得到的错误是来自mail_files
,因为它找不到文件。我已经检查过了,没有其他进程被安排运行来访问这个文件。
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.
对我来说这看起来像是一个路径问题。
在你的输出流语句中,你从来没有定义文件将被写入的路径。这将导致该路径为该应用程序的当前工作目录。当前工作目录的路径不一定与mail__files读取的路径相同(看起来是/usr/local/bin)。
我建议你这样更新你的代码:
OUTPUT STREAM outStr TO /usr/tmp/foo.txt.
和
OUTPUT STREAM stMail THROUGH
"mail_files -f foo@bar.com -t me@here.com -s"subject" -b"/usr/tmp/foo.txt").
…或者您可以尝试将这行更新为指向/usr/local/bin(尽管/usr/local/bin并不适合存放临时文件):
OUTPUT STREAM outStr TO /usr/local/bin/foo.txt.
如果我理解正确的话,Progress会在mail_files使用它之前删除你的文件。
如果是这样,您可以使用唯一文件和cron,删除所有优于某个日期的文件。
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 */
在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.
使用cron,删除今天在那里创建的旧文件- 1(这是一个例子)
我希望它能帮助你。:)