Help replacing os.system call with subprocess call
David Harrison
dave.l.harrison at gmail.com
Mon Apr 7 01:45:33 EDT 2008
On 07/04/2008, David Harrison <dave.l.harrison at gmail.com> wrote:
> On 07/04/2008, David Pratt <fairwinds at eastlink.ca> wrote:
> > Hi. I am trying to replace a system call with a subprocess call. I have
> > tried subprocess.Popen and subprocess.call with but have not been
> > successful. The command line would be:
> >
> > svnadmin dump /my/repository > svndump.db
> >
> > This is what I am using currently:
> >
> > os.system('svnadmin dump %s > %s' % (svn_dir,
> > os.path.join(backup_dir, 'svndump.db')))
> >
> > Many thanks.
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
>
> Hey David,
>
> Your probably want something like the following (code untested and off
> the cuff ;-) )
>
> Cheers
> Dave
>
> ---
>
> import subprocess
>
> p = subprocess.Popen(
> [ "svnadmin", "dump" ],
> stdin=subprocess.PIPE,
> stdout=subprocess.PIPE,
> stderr=subprocess.PIPE,
> close_fds=True
> )
> (child_stdout, child_stdin) = (p.stdout, p.stdin)
>
> f = open('svndump.db')
> f.write(child_stdout.read())
> f.close()
My inner pendant kicked in so I tested the code using [ 'ls', '-lha' ]
and found that the file object should be f = open('svndump.db', 'w')
instead :-)
More information about the Python-list
mailing list