How to run “ ps cax | grep something ” in Python?

前端 未结 5 1233
小蘑菇
小蘑菇 2020-11-29 03:49

How do I run a command with a pipe | in it?

The subprocess module seems complex...

Is there something like

output,error = `ps ca         


        
5条回答
  •  天涯浪人
    2020-11-29 04:07

    import os
    
    os.system('ps -cax|grep something')
    

    If you wanna replace grep argument with some variable:

    os.system('ps -cax|grep '+your_var)
    

提交回复
热议问题