Appending to logfile?

507 views
Skip to first unread message

Jacob JKW

unread,
Jun 11, 2008, 7:43:50 AM6/11/08
to AMPL Modeling Language
Is there a way to specify that AMPL *append* to a logfile?

I've checked the FAQ and AMPL book but can't seem to find a solution
to this. My apologies if I've missed it.

Robert Fourer

unread,
Jun 12, 2008, 8:55:28 PM6/12/08
to am...@googlegroups.com, Ruben Proano

Use ">> filename" to append the output of a command to a specified file.

Actuallly "> filename" also appends the output of a command to a specified
file, except when the file has not yet been opened -- when it has not been
written previously in the AMPL session. In that case "> filename" causes
the file to be overwritten.

Bob Fourer
4...@ampl.com

Jacob JKW

unread,
Jun 19, 2008, 6:57:16 AM6/19/08
to AMPL Modeling Language
On Jun 12, 8:55 pm, "Robert Fourer" <4...@ampl.com> wrote:
> Use ">> filename" to append the output of a command to a specified file.
Although I have found a way around this (I'm just constantly creating
new log files based on the time), this does not appear to work with
writing to with writing logfiles under Windows Vista:

-------------------- Start Example --------------------
ampl: model;
ampl: option log_file (">>foo.txt");
Error executing "option" command:

can't open ">>foo.txt"
ampl: option log_file (">> foo.txt");
Error executing "option" command:

can't open ">> foo.txt"
ampl: option log_file (">>" & "foo.txt");
Error executing "option" command:

can't open ">>foo.txt"
ampl:
-------------------- End Example --------------------

Robert Fourer

unread,
Jun 19, 2008, 11:40:39 AM6/19/08
to am...@googlegroups.com, Jacob JKW

Don't include >> as part of the log file's name. So for example you could use
any of the following forms:

option log_file >> ("foo.txt");

option log_file >> "foo.txt";
option log_file >> foo.txt;

In the first of these, you can use any AMPL string expression in place of
"foo.txt" inside the parentheses. Note that these will only append the output
from the "option log_file" command to file foo.txt, however. If you want to
append output of other commands, you will have to follow them with ">> ..." as
well. If you just want to define a log file to which all results of AMPL
commands are written, then don't use >> in the option log_file statement:

option log_file ("foo.txt");

option log_file "foo.txt";
option log_file foo.txt;

You may need to give the command "close foo.txt" at the end of your AMPL
session to ensure that all output is flushed from buffers to the log file.

Bob Fourer
4...@ampl.com


> -----Original Message-----
> From: am...@googlegroups.com [mailto:am...@googlegroups.com]
> On Behalf Of Jacob JKW
> Sent: Thursday, June 19, 2008 5:57 AM
> To: AMPL Modeling Language

Jacob JKW

unread,
Jun 19, 2008, 12:24:22 PM6/19/08
to AMPL Modeling Language
Yep. That does it and certainly makes sense.

I guess I'm just too accustomed to the Perl mentality.

Thanks again. :)

Jacob JKW

unread,
Jun 20, 2008, 2:46:46 AM6/20/08
to AMPL Modeling Language


On Jun 19, 11:40 am, "Robert Fourer" <4...@ampl.com> wrote:
>  If you just want to define a log file to which all results of AMPL
> commands are written, then don't use >> in the option log_file statement:
>
>    option log_file ("foo.txt");
>    option log_file "foo.txt";
>    option log_file foo.txt;
>
> You may need to give the command "close foo.txt" at the end of your AMPL
> session to ensure that all output is flushed from buffers to the log file.
Although this still begs the question of whether or not one can define
a log file to which all results of AMPL commands are *appended*.

Robert Fourer

unread,
Jun 20, 2008, 1:16:00 PM6/20/08
to am...@googlegroups.com, Jacob JKW

> -----Original Message-----
> From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of Jacob
> JKW
> Sent: Friday, June 20, 2008 1:47 AM
> To: AMPL Modeling Language

Results are always appended to an active log file, until the file is closed or
the session is ended.

I should have mentioned that to explicitly close a log file, you should issue
two commands like:

option log_file '';
close foo.txt;

Otherwise AMPL will automatically re-open a blank file named foo.txt after the
previous foo.txt is closed. Fortunately you don't need to use "close" unless
output to the end of your log file is getting lost when you close your session.

Reply all
Reply to author
Forward
0 new messages