Process command using python
<p>I want to pick up the command and its arguments in Python.</p>

<p>I can use </p>

<pre><code>process=os.popen('ps -elf').read().split("\n")
</code></pre>

<p>and then use regular expression to extract the command but its ugly.</p>

<p>psutils returns a process name but not the actual commands and arguments</p>

<p>Is there a simple way to do this?</p>

<p>The last suggestion is almost correct.
It should be</p>

<pre><code>for p in psutil.process_iter():
   cline = p.cmdline
   if cline: print(cline)
</code></pre>

python process command