Linux shell to python

Barry Scott barry at barrys-emacs.org
Mon Jul 30 23:26:20 CEST 2012


lspci gets all its information from the files in /sys/bus/pci/devices.

You can use os.listdir() to list all the files in the folder and then open
the files you want to get the data you need.

And of course you can write list comprehensions on as many lines as
it take to make the code maintainable.

Barry


On 30 Jul 2012, at 17:55, Paul van der Linden <mail at paultjuh.org> wrote:

> You can do this with one subprocess.Popen and some python commands.
> The alternative is to pipe some subprocess.Popen commands together.
> Or for the quick way out (but I think you better stick with bash scripting then): http://pypi.python.org/pypi/sarge/
> Don't know about it's stability/ubs/etc, never used it.
>  
> -----Original message-----
> From:	Vikas Kumar Choudhary <vikas.choudhary at yahoo.co.in>
> Sent:	Mon 30-07-2012 09:34
> Subject:	Linux shell to python
> To:	python-list at python.org; 
> Dear friends,
> 
> I just joined the group.
> I was trying porting from bash shell to python.
> 
>  
> let me know if someone has tried to implement (grep and PIPE)  shell commands in python `lspci | grep Q | grep  "$isp_str1" | grep "$isp_str2" | cut -c1-7'
>  
> I tried to use python subprocess and OS.Popen modules.
> 
> Thanks & Regard's
> 
> Vikas Kumar Choudhary 
> 
> 
> (Yahoo,MSN-Hotmail,Skype) Messenger = vikas.choudhary
> Please Add Me in Your Messenger List for Better Communication
> P  Please consider the environment before printing this e-mail
> Do not print this email unless it is absolutely necessary. 
> Save papers, Save tree.
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> Note: This e-mail is confidential and may also be privileged, this is for the intended recipients only. If you are not the intended recipient, please delete the message and notify me immediately; you should not copy or use it for any purpose, nor disclose its contents to any other person.
> 
> Notice:  All email and instant messages (including attachments) sent to or from This E-mail id , may be retained, monitored and/or reviewed, or authorized law enforcement personnel, without further notice or consent.
> ----------------------------------------------------------------------------------------------------------------------
>  
> -- 
>  http://mail.python.org/mailman/listinfo/python-list
>  
> -- 
> http://mail.python.org/mailman/listinfo/python-list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120730/b1313b22/attachment.html>


More information about the Python-list mailing list