command line arguments processing: an ugly lpr wrapper
user at domain.invalid
user at domain.invalid
Mon Mar 17 04:03:46 EST 2003
Peter Hansen wrote:
> morden wrote:
>
>>So, my question is:
>>how to make the code a bit less igly
>>and make it take arguments in format -Bfoo in addition to -B foo?
>
>
> Use the getopt module? Much simpler, handles the above
> request.
I dont know if this may add value to your needs, but how about
adding pipes from "popen2" as well if your are using a *nix
system.
Eg,
import popen2
command = "/usr/bin/lpr %s" %(args)
child_stdout, child_stdin, child_stderr = popen2.popen3(command)
out = child_stdout.read()
err = child_stderr.read()
child_stdin.write(message)
out ="%s%s" %(out, child_stdout.read())
err = "%s%s" %(err,child_stderr.read())
child_stdout.close()
child_stderr.close()
status = child_stdin.close()
"out" will contain data from standard output, and "err" for
standard error.
More information about the Python-list
mailing list