Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Linux shell to python (http://www.velocityreviews.com/forums/t948743-re-linux-shell-to-python.html)

Philipp Hagemeister 07-30-2012 10:35 AM

Re: Linux shell to python
 
On 07/30/2012 09:05 AM, Vikas Kumar Choudhary wrote:
> `lspci | grep Q | grep "$isp_str1" | grep "$isp_str2" | cut -c1-7'


The rough Python equivalent would be

import subprocess
[ l.partition(' ')[0] # or l[:7], if you want to copy it verbatim
for l in subprocess.check_output(['lspci']).splitlines()
if 'Q' in l and isp_str1 in l and isp_str2 in l
]

You can also just paste the whole pipeline with the shell=True
parameter. That's not recommended though, and it's hard to correctly
quote strings.

- Philipp


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEAREKAAYFAlAWY3wACgkQ9eq1gvr7CFykBQCeNC7F/jZP8xOWwLvKGruTOhpy
sWYAoI44zaEeM5qKwX2tdH3ZuuFpgrwb
=8rax
-----END PGP SIGNATURE-----



All times are GMT. The time now is 01:34 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.