How can I get dos program running info in python?

Alex Martelli aleax at aleax.it
Tue Jan 8 11:08:19 EST 2002


"Kick" <store_li at sina.com> wrote in message
news:a1f4r1$q5g93$1 at ID-12869.news.dfncis.de...
> I want to use python to make a wrapper for my bcc command line complier. I
> wish I can gather information which bcc return and show them in the python
> program.
>
> Could some one give me some advices?


import os

resultfile = os.popen('bcc ' + ' '.join(flags) + ' '.join(arguments))

text_result = resultfile.readlines()    # or .read(), etc, etc

result_code = resultfile.close()

display_results(result_code, text_result)



The result_code may be examined with functions os.WIFEXITED(result_code),
etc, but only on Unix-like platforms, unfortunately -- on, e.g., Windows,
I believe result_code will None on success, or some numetic mystery on
errors, although that isn't clearly documented in the online docs (I think).


Alex






More information about the Python-list mailing list