os.execl()
Brian E Gallew
geek+ at andrew.cmu.edu
Mon Aug 27 10:01:25 EDT 2001
Then <eli at udel.edu> spoke up and said:
> User-Agent: Pan/0.9.7 (Unix)
> NNTP-Posting-Host: 65.1.161.108
> I have a question about the ececl function from the os module. I was
> trying to write a script to untar a bunch of tarballs in a directory. The
> script looked like this
>
> #!/usr/bin/env python
>
> import os
>
> os.system("ls *.gz > data_file")
>
> tar_file = open("data_file"), "r")
>
> tar_array = tar_file.readlines()
>
> for tarball in tar_array:
> os.execl("tar", "xzvf", tarball)
>
> os.system("rm data_file")
That really won't do what you want it to do. You probably want to do
something like this:
#! /usr/bin/env python
import os,glob
cmd = [ '/usr/bin/tar',
'-x',
'-z',
'-f',
]
tar_file_list = glob.glob('*.tar.gz')
for tar_file in tar_file_list:
if os.fork():
os.wait()
else:
os.exec(cmd[0], cmd + [tar_file,])
More information about the Python-list
mailing list