Using os.system in python to run external programs

Hi all… I’m working on the following script


	sevenZip_KEY = "SOFTWARE\\7-Zip"
	hk_user = _winreg.HKEY_CURRENT_USER
	key = _winreg.OpenKey(hk_user, sevenZip_KEY)
	sevenZipPath = _winreg.QueryValueEx(key, "Path")[0]

	print sevenZipPath

	rarFile = "2B01 - p1121485 - TAY YU - Mars Robot Rig.rar"
	tempPath = "D:/media/work/ADRG/2012 - 2013 - Semester 2/test/2B01 - p1121485 - TAY YU/CA01 - 12-03-16-50-52 - Mars Robot Rig"

	runSevenZip = "\"" + sevenZipPath + "7z.exe\" x -y \"" + tempPath + "/" + rarFile + "\"" + " -o\"" + tempPath + "\""

	print runSevenZip

	testCMD = "\"" + sevenZipPath + "7zFM.exe\""  # <-- this testCMD works if used like below
	# os.system(testCMD)

	os.system(runSevenZip)
	#os.system(r"%s"  %runSevenZip)


basically I want to use 7zip in circumstances where I have to deal with archives other than zip…

First part is to find the path of 7zip…
After that all the various paths and filenames are parsed together into the variable runSevenZip
I then attempt to pass that variable to the system with will throw the following

‘c:\program’ is not recognized as an internal or external program

which I know is something to do with the space. But…

if I paste the output of print runSevenZip directly into a CMD window it works perfect…
or if I use testCMD instead of runSevenZip it’ll accept the space in the path… and launch the GUI of 7zip

any tips or helpful pointers is much appreciated!

cheers

Jamie

and Merry Christmas for the other day… Happy New Year too…

I guess your problem is with space. no accents in the path ?
I use this for example :

import subprocess
subprocess.call(r’“C:\Adobe LightRoom\lightroom.exe” D:_LightRoom_Datas\Family\Family.lrcat’, shell=False)

which give string : “C:\Adobe LightRoom\lightroom.exe” D:_LightRoom_Datas\Family\Family.lrcat

note the single quote (’) for entire string, so the double quotes are in the string
also the r… which allow to not double \

Thx bro! you rock!

Added single quotes as in the following code

os.system(r'"%s"'  %runSevenZip)

Works like a charm…

I’m loving this!

J

[QUOTE=KiboOst;19558]I guess your problem is with space. no accents in the path ?
I use this for example :

import subprocess
subprocess.call(r’“C:\Adobe LightRoom\lightroom.exe” D:_LightRoom_Datas\Family\Family.lrcat’, shell=False)

which give string : “C:\Adobe LightRoom\lightroom.exe” D:_LightRoom_Datas\Family\Family.lrcat

note the single quote (’) for entire string, so the double quotes are in the string
also the r… which allow to not double \[/QUOTE]