سؤال

I am executing a command via Python's subprocess module. How can I view the full command that was executed? For instance, if I submitted ['ls', '-l'], I would like an easy way to see 'ls -l'.

هل كانت مفيدة؟

المحلول

This should work.

ls = subprocess.Popen(['ls', '/tmp'])
cmd = file("/proc/%d/cmdline" % (ls.pid)).read()

See The /proc Filesystem for more info and ideas.

Note that some commands will ask you for privileges.

Of course you could (as Simeon has pointed out) apply join to the list you passed to Popen.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top