AFAIK stdout/stderr semantics vary slightly across platforms so you
are going to run into issues like this when redirecting output,
particularly on windows and linux.
Since you are using subprocess you can retain control of the output.
e.g. you can redirect the output into a file object via the stdout and
stderr kwargs:
output_log = open("output.log", "ab")
check_call(['net', 'stop', 'Apache Tomcat 6'], stdout=output_log,
stderr=output_log)
Alternatively you can use subprocess.PIPE to capture the output and
manage it in your code (since you are using check_call I assume you
are blocking awaiting output anyway). This is probably the preferable
solution.
PS the flush() requirement probably comes from the fact your print
output is buffered, and that you are running the processes without
capturing their stdout/stderr, which means that it's bit of a crap
shoot to see who flushes their buffer first (bet the short running
process always wins).
mick
On Mon, Sep 14, 2009 at 18:40, JammyZ <[email protected]> wrote:
> Hi all,
> I have a 2.6 script here that works OK on Linux, I'm porting it to
> Windows and I cannot get all the output correctly being added to the log
> file.
>
> Linux version runs like this:
> /opt/www/auto-update.py > /opt/www/autoupdate.log 2>&1
>
> Windows version:
> auto-update.py >autoupdate.log 2>&1
>
> The issue is with the output generated by subprocesses, which I execute like
> this:
> check_call(['net', 'stop', 'Apache Tomcat 6'])
>
> Nothing of the output of the previous command ends up in the log file,
> output of print commands is written to the log file correctly though.
>
> I had an issue on Linux, where output would come out of order so I had to
> run sys.stdout.flush after every print statement.
>
> If I run it from the command line everything gets displayed.
>
> Any idea?
>
> Cheers,
> Iker.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Python Ireland" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.ie/group/pythonireland?hl=en
-~----------~----~----~----~------~----~------~--~---