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><code>psutil</code> can get the command line arguments:</p>

<pre><code>import psutil

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

<p>EDIT: updated to fix the issue found by @Keir</p>

python process command