Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-03 Thread jepler
This comes up from time to time.  The brain damage is all Windows', not
Python's.  Here's one thread which seems to suggest a bizarre doubling
of the initial quote of the commandline.

http://groups.google.com/group/comp.lang.python/browse_frm/thread/89d94656ea393d5b/ef40a65017848671


pgp1T5KPY01oo.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-03 Thread Vijay L
I don't have any problems with spaces in the folders.

just for debugging, you could probably try os.system(CMD.replace("\\", "/")

On 3 Dec 2005 19:16:10 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I am trying to run an exe within a python script, but I'm having
> trouble with spaces in the directory name.
>
> The following example will display the usage statement of the program,
> so I know that the space in the path to the exe is being handled
> correctly and that the program was executed.
>
> CMD= r'"C:\program files\some directory\engine\theexe.exe"'
> os.system(CMD)
>
> But the required argument for the exe require a path to a file to be
> specified.  When I try to run the following, os.system(CMD2)
> CMD2= r'"C:\program files\some directory\engine\theexe.exe" "C:\program
> files\some directory\engine\file.txt"'
>
> I get this error:
> Unable to open file C:\Program
>
> So, it looks to me like the space in the path for the argument is
> causing it to fail.  Does anyone have any suggestions that could help
> me out?
> Thanks,
> Steve
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-03 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> This comes up from time to time.  The brain damage is all Windows', not
> Python's. Here's one thread which seems to suggest a bizarre doubling
> of the initial quote of the commandline.
> 
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/89d94656ea393d5b/ef40a65017848671

It can't all be Windows' brain damage, since typing precisely the same 
command at the prompt (at least with the example I'm using) doesn't 
require doubling the initial quote of the command line.  Or, more 
precisely, Windows is brain damaged in at least two different places 
here, and the shell is only one of them...

Also it appears the issue may be more the fact that the second argument 
*also* has quotation marks (regardless of whether it has a space in it 
or not).  It's only then (it seems) that the silly double initial 
quotation mark is required.  Either way, "brain damage" definitely 
describes it.

-Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-03 Thread Bengt Richter
On 3 Dec 2005 19:16:10 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

>I am trying to run an exe within a python script, but I'm having
>trouble with spaces in the directory name.
>
>The following example will display the usage statement of the program,
>so I know that the space in the path to the exe is being handled
>correctly and that the program was executed.
>
>CMD= r'"C:\program files\some directory\engine\theexe.exe"'
>os.system(CMD)
>
>But the required argument for the exe require a path to a file to be
>specified.  When I try to run the following, os.system(CMD2)
>CMD2= r'"C:\program files\some directory\engine\theexe.exe" "C:\program
>files\some directory\engine\file.txt"'
>
>I get this error:
>Unable to open file C:\Program
>
>So, it looks to me like the space in the path for the argument is
>causing it to fail.  Does anyone have any suggestions that could help
>me out?
What version of windows and python are you running?
What happens if you leave out the space in the second quoted string
of CMD2? Does your program execute ok and see it?
What do you get for os.popen(CMD2).read() ?
What do you get if you make a cmd file like echoargs.cmd below
[23:29] C:\pywk\grammar>type c:\util\echoargs.cmd
@echo %*

and substitute echoargs (with path if necessary) in place of your executable in 
CMD2?

Just suggestions to get more symptoms for diagnosis.

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-04 Thread Dan Bishop
[EMAIL PROTECTED] wrote:
> I am trying to run an exe within a python script, but I'm having
> trouble with spaces in the directory name.
...
> So, it looks to me like the space in the path for the argument is
> causing it to fail.  Does anyone have any suggestions that could help
> me out?

Does C:\progra~1\somedi~1\engine\theexe.exe still work?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-04 Thread Leif K-Brooks
Leif K-Brooks wrote:
> It's perfectly reasonable behavior, and it also applies to Linux. The
> shell uses spaces to separate arguments; how do you expect it to know
> that you want a space to be part of the program's name unless you escape it?

I'm sorry, disregard my message. I failed to read the OP properly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-04 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote:
> This comes up from time to time.  The brain damage is all Windows', 
> not Python's.

It's perfectly reasonable behavior, and it also applies to Linux. The
shell uses spaces to separate arguments; how do you expect it to know
that you want a space to be part of the program's name unless you escape it?

> Here's one thread which seems to suggest a bizarre doubling of the 
> initial quote of the commandline.

A better solution would be to use subprocess:
.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-06 Thread rbt
[EMAIL PROTECTED] wrote:
> This comes up from time to time.  The brain damage is all Windows', not
> Python's.  Here's one thread which seems to suggest a bizarre doubling
> of the initial quote of the commandline.
> 
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/89d94656ea393d5b/ef40a65017848671

I do this:

  # remove spaces from ends of filenames.
  for root, dirs, files in os.walk('programs'):
  for fname in files:
  new_fname = fname.strip()
  if new_fname != fname:
  new_path = os.path.join(root,new_fname)
  old_path = os.path.join(root,fname)
  os.renames(old_path,new_path)

  # remove spaces from middle of filenames.
  for root, dirs, files in os.walk('programs'):
  for f in files:
  new_f = string.replace(f, ' ' , '-')
  new_path = os.path.join(root,new_f)
  old_path = os.path.join(root,f)
  os.renames(old_path,new_path)

  # install files.
  for root, dirs, files in os.walk('programs'):
  installable = ['.exe', '.msi', '.EXE', '.MSI']
  for f in files:
  ext = os.path.splitext(f)
  if ext[1] in installable:
  print f
  install = os.system(os.path.join(root,f))


-- 
http://mail.python.org/mailman/listinfo/python-list