[PyQt] Converting an ugly path to a shell path

Hans-Peter Jansen hpj at urpla.net
Mon Sep 13 19:58:04 BST 2010


On Monday 13 September 2010, 20:18:39 AmFreak at web.de wrote:
> Hi,
>
> im using a QFileDialog to let the user select a path that is used later
> in a command send to the shell like this:
>
> retcode = Popen(command + " " + path, shell=True, stdout = PIPE, stderr =
> PIPE)
>
> The problem that occurs now is when the user selects an "ugly" path like
> this /home/user/!" §$/.
> The shell don't understand the special chars so i have to escape them
> with "\" .
> Is there a function that does this ?
> If there isn't i would use a RegEx but I can't even seem to find a list
> containing all special chars :/

First of all, you're pretty much OT here, but anyway, I would try to get rid 
from the shell and run the command directly (shell = False). That way, you 
also prevent the user from abusing this code in harmful ways..

Pete


More information about the PyQt mailing list