On Tue, Feb 23, 2010 at 7:57 AM, Hank Knight <hknight555@gmail.com> wrote:
The following Yaws code returns results to the web.  Instead, I want
it to output the results to a text file named "output.txt"

<erl>
out(A) ->
   Hdrs = A#arg.headers,
   Other = Hdrs#headers.other,
   {ehtml,
      [
       {item, [],
        ["Host: ",
         {span, [], Hdrs#headers.host}]},
       {item, [],
        ["IP Address: ",
         {span, [], f("~p", [inet:peername(A#arg.clisock)])}]},
       {item, [],
        ["Your user agent is: ",
         {span, [], Hdrs#headers.user_agent}]},
       {item, [],
        ["Accept-Charset: ",
         {span, [],
          f("~p", [yaws_api:parse_query(A)]) }]}
       ]}.
</erl>

I think the code below is what you want, adjust the output file pathname to taste.

--steve

<erl>
out(A) ->
    Hdrs = A#arg.headers,
    Other = Hdrs#headers.other,
    Reply = [{item, [],
              ["Host: ",
               {span, [], Hdrs#headers.host}]},
             {item, [],
              ["IP Address: ",
               {span, [], f("~p", [inet:peername(A#arg.clisock)])}]},
             {item, [],
              ["Your user agent is: ",
               {span, [], Hdrs#headers.user_agent}]},
             {item, [],
              ["Accept-Charset: ",
               {span, [],
                f("~p", [yaws_api:parse_query(A)])}]}
            ],
    Html = yaws_api:ehtml_expand(Reply),
    ok = file:write_file("/tmp/output.txt", Html),
    {ehtml, Reply}.
</erl>