[Tutor] Newby Linux Program review + help with regular expressions
Lie Ryan
lie.1296 at gmail.com
Tue Mar 10 12:30:54 CET 2009
David wrote:
> This program generates a report of a Linux System and some important
> ..conf files. The goal is for users to be able to post their information
> and compare with others, ask for help etc. Am I using the subrocess
> module too much because I am comfortable with the commands? Should I
> just write this type of program in bash. I am trying to get rid of all
> the comments generated in the report. I got rid of blank lines and lines
> starting with #. But can not figure out how the get rid of a line like;
> #This is a comment with 5 spaces
> I never programed before so everything is new to me.
> Here is my code;
> http://asterisklinks.com/wiki/doku.php?id=wiki:gentoo_report
> The report it generates is at the bottom. I didn't want to post it all
> here.
> Thanks,
> -david
>
Why are you piping the shell while you ordered the shell to redirect
output to a file, then dumping the pipe?
def uname_report():
p = subprocess.Popen("uname -a >> /root/gentoo_report.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
You should choose either one, use the pipe and write to the report file
yourself (more flexibility) or use the shell >> redirection. Also, I'd
rather not use search and replace if I decided to put the report file
somewhere else.
PS: for unix-style program, the report should be outputted to the stdout
More information about the Tutor
mailing list