You are not logged in.

#1 2007-02-09 09:16:10

Zoranthus
Member
From: muc
Registered: 2006-11-22
Posts: 166

python: spawning processes with n arguments

Hi,

I'm working at a python program that can for example convert file1 to file2 using the convert program:
I start it via os.spawnlp:

os.spawnlp(os.P_WAIT, 'convert', 'convert', 'file1', 'file2')

Now my problem is, I cannot pass any more arguments. I'd like to be able to do something like this:

os.spawnlp(os.P_WAIT, 'convert', 'convert', 'file1', 'file2','-argument1')

but if I try that, I'm only getting alot of ASCII salad.

The other ways of spawning processes I found here don't seem to work either.

Offline

#2 2007-02-09 12:09:57

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: python: spawning processes with n arguments

os.spawnlp(os.P_WAIT, 'convert', ['convert', 'file1', 'file2','-argument1'])

I would recommend getting familiar with subprocess.Popen(). They're pushing it as the defacto now. Many conversion examples are in the docs. help(subprocess.Popen).

Offline

#3 2007-02-09 15:16:24

Zoranthus
Member
From: muc
Registered: 2006-11-22
Posts: 166

Re: python: spawning processes with n arguments

Ok thanks I'll use that then.

I also found out that you can pass commands + arguments as lists, and this works nicely as long as you do pass an argument. If you don't (pass "" instead of "-foo"), weird errors occur. hmm

Offline

Board footer

Powered by FluxBB