[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Command prompt not shown when running Python script with subprocess on Windows

29/05/2014 20:21, ps16thypresenceisfullnessofjoy at gmail.com wrote:
> That's interesting, now I learned something else too. As I said
> before, though, I want users to be able to enter paths in the XML
> file exactly the way they would be entered in a Windows shortcut.


> Since in a Windows shortcut you don't need to put quotes around a
> path that doesn't contain spaces, I want to follow that behavior in
> my program as well.


> So I guess I'll still have to do my "shlex dance" (which for some
> reason I keep on mistyping as "shlex dane" :-)) unless I can learn a
> better way to do it.

It looks like it. Sometimes the behaviour out of the box just doesn't 
cut it. Don't forget, also, that you can subclass, eg, the shlex.shlex 
class and tweak it to do what you need.

> Also, is my calling os.path.expandvars only on the first argument a
> good idea? I want to accept environment variables in my program, but
> I don't want to call os.path.expandvars on all the arguments, because
> I want to let other programs take care of parsing their own
> arguments.

I'd say that's a call only you can make given what you know of your 
requirements. That said, I'm not sure what the "other programs" are 
going to do with any embedded env vars except to expand them as you're 

Ultimately, don't tie yourselves in knots either trying too hard to 
emulate Windows shortcuts or trying too hard to use shlex.split out of 
the box. Decide what constitutes a useful combination of features and 
implement them as simply as you can. [He says, winning the prize for 
stating the obvious :) ]