1 | ' $Id: envSub.vbs 106793 2024-10-30 14:58:06Z vboxsync $
|
---|
2 | '' @file
|
---|
3 | ' VBScript worker for env.cmd
|
---|
4 | '
|
---|
5 |
|
---|
6 | '
|
---|
7 | ' Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
8 | '
|
---|
9 | ' This file is part of VirtualBox base platform packages, as
|
---|
10 | ' available from https://www.virtualbox.org.
|
---|
11 | '
|
---|
12 | ' This program is free software; you can redistribute it and/or
|
---|
13 | ' modify it under the terms of the GNU General Public License
|
---|
14 | ' as published by the Free Software Foundation, in version 3 of the
|
---|
15 | ' License.
|
---|
16 | '
|
---|
17 | ' This program is distributed in the hope that it will be useful, but
|
---|
18 | ' WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | ' General Public License for more details.
|
---|
21 | '
|
---|
22 | ' You should have received a copy of the GNU General Public License
|
---|
23 | ' along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | '
|
---|
25 | ' SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | '
|
---|
27 |
|
---|
28 |
|
---|
29 | ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
---|
30 | ' Header Files
|
---|
31 | ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
---|
32 | ''
|
---|
33 | ' Includes a vbscript file relative to the script.
|
---|
34 | sub IncludeFile(strFilename)
|
---|
35 | dim objFile, objFileSys
|
---|
36 | set objFileSys = WScript.CreateObject("Scripting.FileSystemObject")
|
---|
37 | dim strPath : strPath = objFileSys.BuildPath(objFileSys.GetParentFolderName(Wscript.ScriptFullName), strFilename)
|
---|
38 | set objFile = objFileSys.openTextFile(strPath)
|
---|
39 | executeglobal objFile.readAll()
|
---|
40 | objFile.close
|
---|
41 | set objFileSys = nothing
|
---|
42 | end sub
|
---|
43 |
|
---|
44 | IncludeFile "win\vbscript\helpers.vbs"
|
---|
45 |
|
---|
46 |
|
---|
47 | ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
---|
48 | ' Global Variables '
|
---|
49 | ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
---|
50 | dim g_cntVerbose
|
---|
51 | g_cntVerbose = 1
|
---|
52 |
|
---|
53 |
|
---|
54 | sub LogPrint(str)
|
---|
55 | if g_cntVerbose > 1 then
|
---|
56 | WScript.StdErr.WriteLine "debug: " & str
|
---|
57 | end if
|
---|
58 | end sub
|
---|
59 |
|
---|
60 | sub DbgPrint(str)
|
---|
61 | if g_cntVerbose > 2 then
|
---|
62 | WScript.StdErr.WriteLine "debug: " & str
|
---|
63 | end if
|
---|
64 | end sub
|
---|
65 |
|
---|
66 |
|
---|
67 | ''
|
---|
68 | ' The main() like function.
|
---|
69 | '
|
---|
70 | function Main()
|
---|
71 | Main = 1
|
---|
72 |
|
---|
73 | '
|
---|
74 | ' check that we're not using wscript.
|
---|
75 | '
|
---|
76 | if UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" then
|
---|
77 | Wscript.Echo "This script must be run under CScript."
|
---|
78 | exit function
|
---|
79 | end if
|
---|
80 | SelfTest
|
---|
81 |
|
---|
82 | '
|
---|
83 | ' Get our bearings.
|
---|
84 | '
|
---|
85 | dim strScriptDir
|
---|
86 | strScriptDir = g_objFileSys.GetParentFolderName(Wscript.ScriptFullName)
|
---|
87 |
|
---|
88 | dim strRootDir
|
---|
89 | strRootDir = g_objFileSys.GetParentFolderName(strScriptDir)
|
---|
90 |
|
---|
91 | dim strRealArch
|
---|
92 | strRealArch = Trim(EnvGet("PROCESSOR_ARCHITEW6432"))
|
---|
93 | if strRealArch = "" then strRealArch = Trim(EnvGet("PROCESSOR_ARCHITECTURE"))
|
---|
94 | if strRealArch = "" then strRealArch = "amd64"
|
---|
95 | strRealArch = LCase(strRealArch)
|
---|
96 | if strRealArch <> "amd64" and strRealArch <> "x86" and strRealArch <> "arm64" then
|
---|
97 | MsgError "Unsupported host architecture: " & strRealArch ' quits
|
---|
98 | end if
|
---|
99 |
|
---|
100 | '
|
---|
101 | ' Guest the default configuration.
|
---|
102 | '
|
---|
103 | dim arrTypes : arrTypes = Array("debug", "release", "profile", "strict", "dbgopt")
|
---|
104 | dim arrTargetAndHosts : arrTargetAndHosts = Array("win", "linux", "solaris", "darwin", "os2", "freebsd")
|
---|
105 | dim arrArchitectures : arrArchitectures = Array("x86", "amd64", "arm32", "arm64", "sparc32", "sparc64")
|
---|
106 |
|
---|
107 | dim strType
|
---|
108 | strType = EnvGetDefValid("KBUILD_TYPE", "debug", arrTypes)
|
---|
109 |
|
---|
110 | dim strPathDevTools
|
---|
111 | strPathDevTools= EnvGetDef("KBUILD_DEVTOOLS", g_objFileSys.BuildPath(strRootDir, "tools"))
|
---|
112 |
|
---|
113 | dim strPathkBuild
|
---|
114 | strPathkBuild = EnvGetDef("KBUILD_PATH", g_objFileSys.BuildPath(strRootDir, "kBuild"))
|
---|
115 |
|
---|
116 | dim strTarget, strTargetArch
|
---|
117 | strTarget = EnvGetDefValid("KBUILD_TARGET", "win", arrTargetAndHosts)
|
---|
118 | strTargetArch = EnvGetDefValid("KBUILD_TARGET_ARCH", strRealArch, arrArchitectures)
|
---|
119 |
|
---|
120 | dim strHost, strHostArch
|
---|
121 | strHost = EnvGetDefValid("KBUILD_HOST", "win", arrTargetAndHosts)
|
---|
122 | strHostArch = EnvGetDefValid("KBUILD_HOST_ARCH", strRealArch, arrArchitectures)
|
---|
123 |
|
---|
124 | dim strAltHostArch
|
---|
125 | strAltHostArch = ""
|
---|
126 | if strHostArch = "arm64" then
|
---|
127 | strAltHostArch = "amd64"
|
---|
128 | end if
|
---|
129 |
|
---|
130 | ' Where to look for host related tools.
|
---|
131 | dim arrArchToolsSuffixes : arrArchToolsSuffixes = Array("", strHostArch & ".")
|
---|
132 | if strAltHostArch <> "" then
|
---|
133 | arrArchToolsSuffixes = ArrayAppend(arrArchToolsSuffixes, strAltHostArch & ".")
|
---|
134 | end if
|
---|
135 | if strHostArch <> "x86" and strAltHostArch <> "x86" then
|
---|
136 | arrArchToolsSuffixes = ArrayAppend(arrArchToolsSuffixes, ".x86")
|
---|
137 | end if
|
---|
138 |
|
---|
139 | '
|
---|
140 | ' Parse arguments.
|
---|
141 | '
|
---|
142 | dim arrValueOpts : arrValueOpts = Array("--type", "--arch", "--tmp-script")
|
---|
143 | dim arrCmdToExec : arrCmdToExec = Array()
|
---|
144 | dim blnDashDash : blnDashDash = false
|
---|
145 | dim strChdirTo : strChdirTo = strRootDir
|
---|
146 | dim strTmpScript : strTmpScript = g_objFileSys.BuildPath(strScriptDir, "envtmp.cmd")
|
---|
147 | dim i : i = 0
|
---|
148 | do while i < Wscript.Arguments.Count
|
---|
149 | dim strArg, strValue, off
|
---|
150 | strArg = Wscript.Arguments.item(i)
|
---|
151 | i = i + 1
|
---|
152 | if blnDashDash <> true then
|
---|
153 | ' Does it have an embedded value? Does it take a value?
|
---|
154 | off = InStr(2, strArg, "=")
|
---|
155 | if off <= 0 then off = InStr(2, strArg, ":")
|
---|
156 | if off > 0 then
|
---|
157 | strValue = Mid(strArg, off + 1)
|
---|
158 | strArg = Left(strArg, off - 1)
|
---|
159 | if not ArrayContainsString(arrValueOpts, strArg) then
|
---|
160 | MsgSyntaxError "'" & strArg & "' does not take a value" ' quits
|
---|
161 | end if
|
---|
162 | elseif ArrayContainsString(arrValueOpts, strArg) then
|
---|
163 | if i >= Wscript.Arguments.Count then
|
---|
164 | MsgSyntaxError "'" & strArg & "' takes a value" ' quits
|
---|
165 | end if
|
---|
166 | strValue = Wscript.Arguments.item(i)
|
---|
167 | i = i + 1
|
---|
168 | end if
|
---|
169 |
|
---|
170 | ' Process it.
|
---|
171 | select case strArg
|
---|
172 | ' Build types:
|
---|
173 | case "--type"
|
---|
174 | if not ArrayContainsString(arrTypes, strValue) then
|
---|
175 | MsgSyntaxError "Invalid build type '" & strValue & "'. Valid types: " & ArrayJoinString(arrTypes, ", ") ' quits
|
---|
176 | else
|
---|
177 | strType = strValue
|
---|
178 | end if
|
---|
179 | case "--release"
|
---|
180 | strType = "release"
|
---|
181 | case "--debug"
|
---|
182 | strType = "debug"
|
---|
183 | case "--strict"
|
---|
184 | strType = "strict"
|
---|
185 | case "--dbgopt"
|
---|
186 | strType = "dbgopt"
|
---|
187 |
|
---|
188 | ' Target architecture:
|
---|
189 | case "--arch"
|
---|
190 | if not ArrayContainsString(arrArchitectures, strValue) then
|
---|
191 | MsgSyntaxError "Invalid target architecture'" & strValue & "'. Valid ones: " _
|
---|
192 | & ArrayJoinString(arrArchitectures, ", ") ' quits
|
---|
193 | else
|
---|
194 | strTargetArch = strValue
|
---|
195 | end if
|
---|
196 | case "--amd64"
|
---|
197 | strTargetArch = "amd64"
|
---|
198 | case "--x86"
|
---|
199 | strTargetArch = "amd64"
|
---|
200 | case "--arm32"
|
---|
201 | strTargetArch = "arm32"
|
---|
202 | case "--arm64"
|
---|
203 | strTargetArch = "amd64"
|
---|
204 |
|
---|
205 | ' Verbosity, env.sh compatibility and stuff
|
---|
206 | case "--quiet"
|
---|
207 | g_cntVerbose = 0
|
---|
208 | case "--verbose"
|
---|
209 | g_cntVerbose = g_cntVerbose + 1
|
---|
210 | case "--chdir"
|
---|
211 | strChdirTo = strValue
|
---|
212 | case "--no-chdir"
|
---|
213 | strChdirTo = ""
|
---|
214 |
|
---|
215 | ' Internal.
|
---|
216 | case "--tmp-script"
|
---|
217 | strTmpScript = strValue
|
---|
218 |
|
---|
219 | ' Standard options
|
---|
220 | case "-h", "-?", "--help"
|
---|
221 | Print "Sets the VBox development shell environment on Windows."
|
---|
222 | Print "usage: env.cmd [--type <type> | --release | --debug | --strict | --dbgopt]"
|
---|
223 | Print " [--arch <arch> | --amd64 | --x86 | --arm32 | --arm64]"
|
---|
224 | Print " [--no-chdir | --chdir <dir>] [--quiet | --verbose]"
|
---|
225 | Print " [--] [prog] [args...]"
|
---|
226 | Print "usage: env.cmd [--help | -h | -?]"
|
---|
227 | Print "usage: env.cmd [--version | -V]"
|
---|
228 | Main = 0
|
---|
229 | exit function
|
---|
230 | case "-V", "--version"
|
---|
231 | Print "x.y"
|
---|
232 | Main = 0
|
---|
233 | exit function
|
---|
234 |
|
---|
235 | case "--"
|
---|
236 | blnDashDash = True
|
---|
237 |
|
---|
238 | case else
|
---|
239 | MsgSyntaxError "Unknown option: " & strArg
|
---|
240 | end select
|
---|
241 | else
|
---|
242 | ' cscript may eat quoting... So we should consider using some windows API to get the raw command line
|
---|
243 | ' and look for the dash-dash instead. Maybe.
|
---|
244 | arrCmdToExec = ArrayAppend(arrCmdToExec, strArg)
|
---|
245 | end if
|
---|
246 | loop
|
---|
247 |
|
---|
248 | '
|
---|
249 | ' Set up the environment.
|
---|
250 | '
|
---|
251 | dim str1
|
---|
252 |
|
---|
253 | EnvSet "KBUILD_PATH", UnixSlashes(strPathkBuild)
|
---|
254 | EnvSet "KBUILD_DEVTOOLS", UnixSlashes(strPathDevTools)
|
---|
255 | EnvSet "KBUILD_TYPE", strType
|
---|
256 | EnvSet "KBUILD_TARGET", strTarget
|
---|
257 | EnvSet "KBUILD_TARGET_ARCH", strTargetArch
|
---|
258 | EnvSet "KBUILD_HOST", strHost
|
---|
259 | EnvSet "KBUILD_HOST_ARCH", strHostArch
|
---|
260 |
|
---|
261 | ' Remove legacy variables.
|
---|
262 | dim arrObsolete
|
---|
263 | arrObsolete = Array("BUILD_TYPE", "BUILD_TARGET", "BUILD_TARGET_ARCH", "BUILD_PLATFORM", "BUILD_PLATFORM_ARCH", _
|
---|
264 | "PATH_DEVTOOLS", "KBUILD_TARGET_CPU", "KBUILD_PLATFORM_CPU")
|
---|
265 | for each str1 in arrObsolete
|
---|
266 | EnvUnset str1
|
---|
267 | next
|
---|
268 |
|
---|
269 | ' cleanup path before we start adding to it
|
---|
270 | for each str1 in arrArchitectures
|
---|
271 | EnvRemovePathItem "Path", DosSlashes(strPathkBuild & "\bin\win." & str1), ";"
|
---|
272 | EnvRemovePathItem "Path", DosSlashes(strPathkBuild & "\bin\win." & str1 & "\wrappers"), ";"
|
---|
273 | EnvRemovePathItem "Path", DosSlashes(strPathDevTools & "\win." & str1) & "\bin", ";"
|
---|
274 | next
|
---|
275 |
|
---|
276 | '
|
---|
277 | ' We skip the extra stuff like gnuwin32, windbg, cl.exe and mingw64 if
|
---|
278 | ' there is a command to execute.
|
---|
279 | '
|
---|
280 | if ArraySize(arrCmdToExec) = 0 then
|
---|
281 | ' Add the kbuild wrapper directory to the end of the path, these take
|
---|
282 | ' precedence over the dated gnuwin32 stuff.
|
---|
283 | EnvAppendPathItem "Path", DosSlashes(strPathkBuild & "\bin\win." & strHostArch & "\wrappers"), ";"
|
---|
284 | if strAltHostArch <> "" then EnvAppendPathItem "Path", DosSlashes(strPathkBuild & "\bin\win." & strAltHostArch & "\wrappers"), ";"
|
---|
285 |
|
---|
286 | ' Add some gnuwin32 tools to the end of the path.
|
---|
287 | EnvAppendPathItem "Path", DosSlashes(strPathDevTools & "\win.x86\gnuwin32\r1\bin"), ";"
|
---|
288 |
|
---|
289 | ' Add the newest debugger we can find to the front of the path.
|
---|
290 | dim strDir, blnStop
|
---|
291 | bldExitLoop = false
|
---|
292 | for each str1 in arrArchToolsSuffixes
|
---|
293 | strDir = strPathDevTools & "\win" & str1 & "\sdk"
|
---|
294 | for each strSubDir in GetSubdirsStartingWithRVerSorted(strDir, "v")
|
---|
295 | if FileExists(strDir & "\" & strSubDir & "\Debuggers\" & XlateArchitectureToWin(strHostArch) & "\windbg.exe") then
|
---|
296 | EnvPrependPathItem "Path", DosSlashes(strDir & "\" & strSubDir & "\Debuggers\" & XlateArchitectureToWin(strHostArch)), ";"
|
---|
297 | bldExitLoop = true
|
---|
298 | exit for
|
---|
299 | end if
|
---|
300 | next
|
---|
301 | if bldExitLoop then exit for
|
---|
302 | next
|
---|
303 |
|
---|
304 | ' Add VCC to the end of the path.
|
---|
305 | dim str2, strDir2, arrVccOldBinDirs
|
---|
306 | arrVccOldBinDirs = Array("\bin\" & strHostArch & "_" & strTargetArch, "\bin\" & strTargetArch, "\bin")
|
---|
307 | bldExitLoop = false
|
---|
308 | for each str1 in Array("amd64", "x86")
|
---|
309 | for each strDir in GetSubdirsStartingWithRVerSorted(strPathDevTools & "\win." & str1 & "\vcc", "v")
|
---|
310 | strDir = strPathDevTools & "\win." & str1 & "\vcc\" & strDir
|
---|
311 | if DirExists(strDir & "\Tools\MSVC") then
|
---|
312 | for each strDir2 in GetSubdirsStartingWithRVerSorted(strDir & "\Tools\MSVC", "1")
|
---|
313 | strDir2 = strDir & "\Tools\MSVC\" & strDir2 & "\bin\Host" & XlateArchitectureToWin(strHostArch) _
|
---|
314 | & "\" & XlateArchitectureToWin(strTargetArch)
|
---|
315 | if FileExists(strDir2 & "\cl.exe") then
|
---|
316 | EnvAppendPathItem "Path", DosSlashes(strDir2), ";"
|
---|
317 | if strTargetArch <> strHostArch then
|
---|
318 | EnvAppendPathItem "Path", DosSlashes(PathStripFilename(strDir2) & "\" & XlateArchitectureToWin(strHostArch)), ";"
|
---|
319 | end if
|
---|
320 | bldExitLoop = true
|
---|
321 | exit for
|
---|
322 | end if
|
---|
323 | next
|
---|
324 | elseif DirExists(strDir & "\bin") then
|
---|
325 | for each str2 in arrVccOldBinDirs
|
---|
326 | if FileExists(strDir & str2 & "\cl.exe") then
|
---|
327 | EnvAppendPathItem "Path", DosSlashes(strDir & str2), ";"
|
---|
328 | if str2 <> "\bin" then EnvAppendPathItem "Path", DosSlashes(strDir & "bin"), ";"
|
---|
329 | bldExitLoop = true
|
---|
330 | exit for
|
---|
331 | end if
|
---|
332 | next
|
---|
333 | end if
|
---|
334 | if bldExitLoop then exit for
|
---|
335 | next
|
---|
336 | if bldExitLoop then exit for
|
---|
337 | next
|
---|
338 |
|
---|
339 | ' Add mingw64 if it's still there.
|
---|
340 | if strHostArch = "amd64" or strTargetArch = "amd64" then
|
---|
341 | str1 = strPathDev & "win.amd64\mingw-64\r1\bin"
|
---|
342 | if DirExists(str1) then EnvAppendPathItem "Path", DosSlashes(str1), ";"
|
---|
343 | end if
|
---|
344 | end if
|
---|
345 |
|
---|
346 | ' Add the output tools and bin directories to the fron of the path, taking PATH_OUT_BASE into account.
|
---|
347 | dim strOutDir
|
---|
348 | strOutDir = EnvGetDef("PATH_OUT_BASE", strRootDir & "\out")
|
---|
349 | strOutDir = strOutDir & "\" & strTarget & "." & strTargetArch & "\" & strType
|
---|
350 | EnvPrependPathItem "Path", DosSlashes(strOutDir & "\bin\tools"), ";"
|
---|
351 | EnvPrependPathItem "Path", DosSlashes(strOutDir & "\bin"), ";"
|
---|
352 |
|
---|
353 | ' Add kbuild binary directory to the front the the path.
|
---|
354 | if strAltHostArch <> "" then EnvPrependPathItem "Path", DosSlashes(strPathkBuild & "\bin\win." & strAltHostArch), ";"
|
---|
355 | EnvPrependPathItem "Path", DosSlashes(strPathkBuild & "\bin\win." & strHostArch), ";"
|
---|
356 |
|
---|
357 | ' Finally, add the relevant tools/**/bin directories to the front of the path.
|
---|
358 | EnvPrependPathItem "Path", DosSlashes(strPathDevTools & "\bin"), ";"
|
---|
359 | if strHostArch = "amd64" then EnvPrependPathItem "Path", DosSlashes(strPathDevTools & "\win.x86\bin"), ";"
|
---|
360 | if strAltHostArch <> "" then EnvPrependPathItem "Path", DosSlashes(strPathDevTools & "\win." & strAltHostArch & "\bin"), ";"
|
---|
361 | EnvPrependPathItem "Path", DosSlashes(strPathDevTools & "\win." & strHostArch) & "\bin", ";"
|
---|
362 |
|
---|
363 | '
|
---|
364 | ' Export if we are not executing a program.
|
---|
365 | '
|
---|
366 | Main = g_rcScript
|
---|
367 | if ArraySize(arrCmdToExec) = 0 then
|
---|
368 | dim objTmpScript
|
---|
369 | set objTmpScript = g_objFileSys.CreateTextFile(strTmpScript, true, false)
|
---|
370 | objTmpScript.WriteLine
|
---|
371 |
|
---|
372 | for each str1 in Array("Path", "KBUILD_PATH", "KBUILD_DEVTOOLS", "KBUILD_TYPE", _
|
---|
373 | "KBUILD_TARGET", "KBUILD_TARGET_ARCH", "KBUILD_HOST", "KBUILD_HOST_ARCH")
|
---|
374 | objTmpScript.WriteLine "SET " & str1 & "=" & EnvGet(str1)
|
---|
375 | next
|
---|
376 | for each str1 in arrObsolete
|
---|
377 | if EnvExists(str1) then objTmpScript.WriteLine "SET " & str1 & "="
|
---|
378 | next
|
---|
379 |
|
---|
380 | if strChdirTo <> "" then
|
---|
381 | objTmpScript.WriteLine "CD """ & strChdirTo & """"
|
---|
382 | if Mid(strChdirTo, 2, 1) = ":" then
|
---|
383 | objTmpScript.WriteLine Left(strChdirTo, 2)
|
---|
384 | end if
|
---|
385 | end if
|
---|
386 |
|
---|
387 | objTmpScript.Close()
|
---|
388 | '
|
---|
389 | ' Run the specified program.
|
---|
390 | '
|
---|
391 | ' We must redirect stderr to stdout here, because vbscript doesn't seem to
|
---|
392 | ' have any way to reuse the same console/stdout/stererr as we use (Exec
|
---|
393 | ' creates two pipes, Run a new console), nor can vbscript service two
|
---|
394 | ' TextStream/pipe objects at the same time without the risk of deadlocking
|
---|
395 | ' with the child process (we read stdout, child waits for stderr space).
|
---|
396 | '
|
---|
397 | ' So, to make it work we use kmk_redirect.exe to stuff everything into stderr
|
---|
398 | ' and ignore stdout.
|
---|
399 | '
|
---|
400 | else
|
---|
401 | if strChdirTo <> "" then
|
---|
402 | g_objShell.CurrentDirectory = strChdirTo
|
---|
403 | end if
|
---|
404 |
|
---|
405 | ' Prepate the command line.
|
---|
406 | dim strCmdLine, str
|
---|
407 | strCmdLine = """" & DosSlashes(strPathkBuild) & "\bin\win." & strHostArch & "\kmk_redirect.exe"" -d1=2 -c0 -- " _
|
---|
408 | & """" & arrCmdToExec(0) & """"
|
---|
409 | for i = 1 to UBound(arrCmdToExec)
|
---|
410 | str = arrCmdToExec(i)
|
---|
411 | if InStr(1, str, " ") > 0 then '' @todo There is more stuff that needs escaping
|
---|
412 | strCmdLine = strCmdLine & " """ & str & """"
|
---|
413 | else
|
---|
414 | strCmdLine = strCmdLine & " " & str
|
---|
415 | end if
|
---|
416 | next
|
---|
417 |
|
---|
418 | ' Start it.
|
---|
419 | if g_cntVerbose > 0 then MsgInfo "Executing command: " & strCmdLine
|
---|
420 | dim objChild
|
---|
421 | set objChild = g_objShell.Exec(strCmdLine)
|
---|
422 |
|
---|
423 | ' The fun output / wait. As mention above, we only need to bother with stderr here.
|
---|
424 | dim cMsSleepMin : cMsSleepMin = 8
|
---|
425 | dim cMsSleepMax : cMsSleepMax = 92
|
---|
426 | dim cMsSleep : cMsSleep = cMsSleepMin
|
---|
427 | do while objChild.Status = 0
|
---|
428 | if not objChild.StdErr.AtEndOfStream then ' Seems this bugger might do a 0x80
|
---|
429 | WScript.StdErr.WriteLine objChild.StdErr.ReadLine()
|
---|
430 | cMsSleep = cMsSleepMin
|
---|
431 | elseif objChild.Status = 0 then
|
---|
432 | Wscript.Sleep cMsSleep
|
---|
433 | ' We probably only end up here once stderr is closed/disconnected (i.e. never).
|
---|
434 | ' This was originally written with the idea that AtEndOfStream would use
|
---|
435 | ' PeekNamedPipe to see if there were anything to read, rather than block.
|
---|
436 | ' Let's keep it for now.
|
---|
437 | if cMsSleep < cMsSleepMax then cMsSleep = cMsSleep + 8
|
---|
438 | end if
|
---|
439 | loop
|
---|
440 |
|
---|
441 | ' Flush any remaining output on the offchance that we could get out of the above loop with pending output.
|
---|
442 | WScript.StdErr.Write strStdErr & objChild.StdErr.ReadAll()
|
---|
443 | WScript.StdOut.Write strStdOut & objChild.StdOut.ReadAll()
|
---|
444 |
|
---|
445 | ' Return the exit code to our parent.
|
---|
446 | if g_cntVerbose > 0 then MsgInfo "Exit code = " & objChild.ExitCode
|
---|
447 | Main = objChild.ExitCode
|
---|
448 | end if
|
---|
449 | end function
|
---|
450 |
|
---|
451 | '
|
---|
452 | ' What crt0.o typically does:
|
---|
453 | '
|
---|
454 | WScript.Quit(Main())
|
---|
455 |
|
---|