popen eating quotes?
belred1 at yahoo.com
Mon Aug 4 03:32:50 CEST 2003
"Rob Williscroft" <rtw at freenet.REMOVE.co.uk> wrote in message
news:Xns93CDD4975617ukcoREMOVEfreenetrtw at 22.214.171.124...
> Bryan wrote in news:LOgXa.57808$o%2.28737 at sccrnsc02:
> >>>> import os
> >>>> def run_args(arg):
> > ... i, o = os.popen4('"c:/program files/test/args.bat" -vv %s' % arg)
> > ... print o.read()
> > ...
> >>>> run_args('"this is a very long path with spaces"')
> > 'c:/program' is not recognized as an internal or external command,
> > operable program or batch file.
> I just got the following working where os.getcwd() is returning:
> 'C:\\Documents and Settings\\Rob\\Desktop'
> >>> def f():
> ... i, o = os.popen4( "\"" + os.getcwd() + "\\aaa.bat\"" )
> ... print o.read()
> ... i.close()
> ... o.close()
> If this dosen't help, then (sound of large hammer being removed
> from a tool box) maybe this will:
> def g(arg):
> x = os.getcwd()
> os.chdir( "c:/program files/test/" )
> i, o = os.popen4( 'args.bat -vv %s' % arg )
> os.chdir( x )
> print o.read()
thanks... this is exactly the solution i came up with too. it does remove
the path, but not the spaces in the file name. i _might_ be able to live
with this hack though.
the code i'm porting to python is from perl, and the perl code doesn't have
the popen issue.
@xxxoutput=`xxx -vv "$file"`;
now i won't be able show how cool python is :(
More information about the Python-list