Can we pass some arguments to system("cmdline")?

Leif K-Brooks eurleif at ecritters.biz
Mon Jun 20 02:56:11 EDT 2005


Didier C wrote:
> E.g in Perl, we can do something like:
> 
> $dir="/home/cypher";
> 
> system("ls $dir");
> 
> Is there a way to reproduce the same thing in Python?

system("ls %s" % dir)

But you should really be using subprocess for security (so that if
dir=="/home/foo; rm -rf /" nothing bad will happen):

import subprocess
subprocess.Popen(['ls', dir])



More information about the Python-list mailing list