PDA

View Full Version : PyQT4: application won't start because of spaces in path Qprocess



jaybstory
1st February 2010, 01:20
Hello,

I'm trying to start windows media player using Qprocess (for a windows xp operating system). However, when I run my code, it won't start. I am assuming it is because of the spaces in the path name. How do I fix my code so that it will work with paths that have spaces in it? I am using pyqt4. Thank you in advance.






if sys.platform == 'win32':
p = QtCore.QProcess(self)
p.setWorkingDirectory("C:\Program Files\Windows Media Player")
p.start('wmplayer')

bender86
2nd February 2010, 11:00
Have you tried quoting the path, or escaping the spaces? And also remember to escape slashes: \\

p.setWorkingDirectory("\"C:\\Program Files\\Windows Media Player\"")
p.setWorkingDirectory("C:\\Program\\ Files\\Windows Media Player")

jaybstory
3rd February 2010, 00:16
Hello,

yes, I have tried both, however my gui is still not opening the program. Do you or anyone else have any other suggestions?

nikhilqt
3rd February 2010, 06:09
Try this,


QFile file("dummy.bat");

if(!file.open(QIODevice::WriteOnly) )
return;

file.write(QString("\"C:/Program Files/Windows Media Player/wmplayer\"").toAscii());
file.close();

p->start("dummy.bat");

if( p->waitForFinished() )
{
file.remove();
return;
}

bender86
3rd February 2010, 15:17
This is weird. I managed to open a program with the complete path (still have to quote it) but not to open a program in the current working dir. Anyway, I found that if you specify a non existent working directory you will not be able to start any program, neither one in system path (I tried with cmd.exe); so the problem should be not within setWorkingDirectory().
I hope hat someone with more knowledge about PyQt could help.

p = QtCore.QProcess()
p.start("\"C:\\Program Files\\Internet Explorer\\iexplore.exe\"")
# This works.

...

p = QtCore.QProcess()
p.setWorkingDirectory("C:\\Program Files\\Internet Explorer")
p.start("cmd.exe")
# This works.

...

p = QtCore.QProcess()
p.setWorkingDirectory("C:\\I do not exist")
p.start("cmd.exe")
# This DOES NOT works.

...

p = QtCore.QProcess()
p.setWorkingDirectory("C:\\Program Files\\Internet Explorer")
p.start("iexplorer.exe")
# This DOES NOT works.

jaybstory
3rd February 2010, 23:50
Thanks nikhilqt & bender86. I was able to solve the problem with your guys help!