11local http = require (" http" )
22local html = require (" html" )
33local json = require (" json" )
4+ local windowsCommand = require (" windows_command" )
45
56-- get mirror
67local PYTHON_URL = " https://www.python.org/ftp/python/"
@@ -91,7 +92,7 @@ function windowsInstallMsi(path, url, version, filename)
9192
9293 -- Install msi
9394 print (" Installing python..." )
94- local command = ' msiexec /quiet /a ' .. qInstallFile .. ' TargetDir= ' .. qInstallPath
95+ local command = windowsCommand . msi ( qInstallFile , qInstallPath )
9596 local exitCode = os.execute (command )
9697 os.remove (qInstallFile )
9798 if exitCode ~= 0 then
@@ -104,7 +105,7 @@ function windowsInstallMsi(path, url, version, filename)
104105 if file then
105106 io.close (file )
106107 print (" Installing pip..." )
107- local command = qInstallPath .. ' \\ python -E -s -m ensurepip -U --default-pip > NUL '
108+ local command = windowsCommand . native ( qInstallPath .. ' \\ python.exe ' , { ' -E ' , ' -s ' , ' -m ' , ' ensurepip' , ' -U ' , ' --default-pip' })
108109 local exitCode = os.execute (command )
109110 if exitCode ~= 0 then
110111 error (" Install pip failed. exit " .. exitCode )
@@ -134,7 +135,7 @@ function windowsInstallExe(path, url, version, filename)
134135 -- Extract
135136 print (" Extracting installer..." )
136137 local wixBin = RUNTIME .pluginDirPath .. ' \\ bin\\ WiX\\ dark.exe'
137- local command = wixBin .. " -x " .. qInstallPath .. ' \\ ' .. qInstallFile .. ' > NUL '
138+ local command = windowsCommand . native ( wixBin , { ' -x ' , qInstallPath , qInstallFile })
138139 local exitCode = os.execute (command )
139140 if exitCode ~= 0 then
140141 error (" Extract failed" )
@@ -150,25 +151,30 @@ function windowsInstallExe(path, url, version, filename)
150151
151152 -- Install msi
152153 print (" Installing python..." )
153- local files = io.popen (" dir /b " .. msiPath ):lines ()
154+ local listing , listErr = io.popen (windowsCommand .files (msiPath ))
155+ if not listing then
156+ error (' Failed to list installer packages: ' .. tostring (listErr ))
157+ end
158+ local files = listing :lines ()
154159 for file in files do
155160 if file :match (" %.msi$" ) then
156- local command = " msiexec /quiet /a " .. msiPath .. ' \\ ' .. file .. " TargetDir= " .. qInstallPath
161+ local command = windowsCommand . msi ( msiPath .. ' \\ ' .. file , qInstallPath )
157162 local exitCode = os.execute (command )
158163 if exitCode ~= 0 then
159164 error (" Install msi failed: " .. file )
160165 end
161166 os.remove (qInstallPath .. ' \\ ' .. file )
162167 end
163168 end
169+ listing :close ()
164170
165171 -- Install pip
166172 print (" Installing pip..." )
167173 local ensurepipPath = qInstallPath .. " \\ Lib\\ ensurepip\\ __init__.py"
168174 local file = io.open (ensurepipPath , " r" )
169175 if file then
170176 io.close (file )
171- local command = qInstallPath .. ' \\ python -E -s -m ensurepip -U --default-pip > NUL '
177+ local command = windowsCommand . native ( qInstallPath .. ' \\ python.exe ' , { ' -E ' , ' -s ' , ' -m ' , ' ensurepip' , ' -U ' , ' --default-pip' })
172178 local exitCode = os.execute (command )
173179 if exitCode ~= 0 then
174180 error (" Install pip failed. exit " .. exitCode )
@@ -190,16 +196,20 @@ function windowsInstallExe(path, url, version, filename)
190196 local files = {qInstallPath .. " \\ python" .. major .. " .exe" , qInstallPath .. " \\ python" .. majorMinor .. " .exe" ,
191197 qInstallPath .. " \\ python" .. majorDotMinor .. " .exe" }
192198 for _ , file in ipairs (files ) do
193- local command = ' copy /y ' .. pythonExePath .. ' ' .. file .. ' > NUL'
194- os.execute (command )
199+ local command = windowsCommand .copy (pythonExePath , file )
200+ if os.execute (command ) ~= 0 then
201+ error (' Failed to create Python executable alias: ' .. file )
202+ end
195203 end
196204
197205 -- pythonw.exe
198206 local files = {qInstallPath .. " \\ pythonw" .. major .. " .exe" , qInstallPath .. " \\ pythonw" .. majorMinor .. " .exe" ,
199207 qInstallPath .. " \\ pythonw" .. majorDotMinor .. " .exe" }
200208 for _ , file in ipairs (files ) do
201- local command = ' copy /y ' .. pythonwExePath .. ' ' .. file .. ' > NUL'
202- os.execute (command )
209+ local command = windowsCommand .copy (pythonwExePath , file )
210+ if os.execute (command ) ~= 0 then
211+ error (' Failed to create Python executable alias: ' .. file )
212+ end
203213 end
204214
205215 -- Check if venvlauncher exists
@@ -214,8 +224,10 @@ function windowsInstallExe(path, url, version, filename)
214224 qInstallPath .. " \\ Lib\\ venv\\ scripts\\ nt\\ pythonw" .. majorMinor .. " .exe" ,
215225 qInstallPath .. " \\ Lib\\ venv\\ scripts\\ nt\\ pythonw" .. majorDotMinor .. " .exe" }
216226 for _ , file in ipairs (files ) do
217- local command = ' copy /y ' .. venvlauncherExePath .. ' ' .. file .. ' > NUL'
218- os.execute (command )
227+ local command = windowsCommand .copy (venvlauncherExePath , file )
228+ if os.execute (command ) ~= 0 then
229+ error (' Failed to create Python venv executable alias: ' .. file )
230+ end
219231 end
220232 end
221233
0 commit comments