Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Linux shell to python

Reply
Thread Tools

Re: Linux shell to python

 
 
Philipp Hagemeister
Guest
Posts: n/a
 
      07-30-2012
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-----

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash shell to Python shell? edwithad Python 4 09-28-2009 07:56 AM
Re: How to pass shell variable to shell script from python D'Arcy J.M. Cain Python 0 02-27-2008 01:56 PM
Re: How to pass shell variable to shell script from python Gerardo Herzig Python 1 02-27-2008 12:19 PM
Re: How to pass shell variable to shell script from python Christian Heimes Python 0 02-27-2008 10:53 AM
can I run unix shell command in the ModelSim shell? clinton__bill@hotmail.com VHDL 2 02-18-2005 10:04 PM



Advertisments