@@ -52,6 +52,7 @@ var ShallowCloneDepth int
5252var logFile * os.File
5353var SkipNewtCompat bool
5454var SkipSyscfgRepoHash bool
55+ var HideLoadCmdOutput bool
5556
5657func ParseEqualsPair (v string ) (string , string , error ) {
5758 s := strings .Split (v , "=" )
@@ -352,38 +353,14 @@ func EnvironAsMap() (map[string]string, error) {
352353 return m , nil
353354}
354355
355- // Execute the specified process and block until it completes. Additionally,
356- // the amount of combined stdout+stderr output to be logged to the debug log
357- // can be restricted to a maximum number of characters.
358- //
359- // @param cmdStrs The "argv" strings of the command to execute.
360- // @param env Additional key,value pairs to inject into the
361- // child process's environment. Specify null
362- // to just inherit the parent environment.
363- // @param logCmd Whether to log the command being executed.
364- // @param maxDbgOutputChrs The maximum number of combined stdout+stderr
365- // characters to write to the debug log.
366- // Specify -1 for no limit; 0 for no output.
367- //
368- // @return []byte Combined stdout and stderr output of process.
369- // @return error NewtError on failure. Use IsExit() to
370- // determine if the command failed to execute
371- // or if it just returned a non-zero exit
372- // status.
373- func ShellCommandLimitDbgOutput (
374- cmdStrs []string , env map [string ]string , logCmd bool ,
375- maxDbgOutputChrs int ) ([]byte , error ) {
356+ func ShellCommandInit (cmdStrs []string , env map [string ]string ) (* exec.Cmd , error ) {
376357
377358 var name string
378359 var args []string
379360
380361 // Escape special characters for Windows.
381362 fixupCmdArgs (cmdStrs )
382363
383- if logCmd {
384- LogShellCmd (cmdStrs , env )
385- }
386-
387364 if ExecuteShell && (runtime .GOOS == "linux" || runtime .GOOS == "darwin" ) {
388365 cmd := strings .Join (cmdStrs , " " )
389366 name = "/bin/sh"
@@ -418,6 +395,75 @@ func ShellCommandLimitDbgOutput(
418395 cmd .Env = EnvVarsToSlice (m )
419396 }
420397
398+ return cmd , nil
399+ }
400+
401+ // Execute the specified process and block until it completes. Process'
402+ // output will be redirected to the stdout and stderr if output log is enabled
403+ //
404+ // @param cmdStrs The "argv" strings of the command to execute.
405+ // @param env Additional key,value pairs to inject into the
406+ // child process's environment. Specify null
407+ // to just inherit the parent environment.
408+ // @param logCmd Whether to log the command being executed.
409+ // @param maxDbgOutputChrs Whether to log the output of the process
410+ //
411+ // @return error NewtError on failure. Use IsExit() to
412+ // determine if the command failed to execute
413+ // or if it just returned a non-zero exit
414+ // status.
415+ func ShellCommandStreamOutput (
416+ cmdStrs []string , env map [string ]string , logCmd bool ,
417+ logOutput bool ) error {
418+
419+ cmd , err := ShellCommandInit (cmdStrs , env )
420+ if err != nil {
421+ return err
422+ }
423+
424+ if logCmd {
425+ LogShellCmd (cmdStrs , env )
426+ }
427+
428+ if logOutput {
429+ cmd .Stdout = os .Stdout
430+ cmd .Stderr = os .Stderr
431+ }
432+
433+ return cmd .Run ()
434+ }
435+
436+ // Execute the specified process and block until it completes. Additionally,
437+ // the amount of combined stdout+stderr output to be logged to the debug log
438+ // can be restricted to a maximum number of characters.
439+ //
440+ // @param cmdStrs The "argv" strings of the command to execute.
441+ // @param env Additional key,value pairs to inject into the
442+ // child process's environment. Specify null
443+ // to just inherit the parent environment.
444+ // @param logCmd Whether to log the command being executed.
445+ // @param maxDbgOutputChrs The maximum number of combined stdout+stderr
446+ // characters to write to the debug log.
447+ // Specify -1 for no limit; 0 for no output.
448+ //
449+ // @return []byte Combined stdout and stderr output of process.
450+ // @return error NewtError on failure. Use IsExit() to
451+ // determine if the command failed to execute
452+ // or if it just returned a non-zero exit
453+ // status.
454+ func ShellCommandLimitDbgOutput (
455+ cmdStrs []string , env map [string ]string , logCmd bool ,
456+ maxDbgOutputChrs int ) ([]byte , error ) {
457+
458+ cmd , err := ShellCommandInit (cmdStrs , env )
459+ if err != nil {
460+ return nil , err
461+ }
462+
463+ if logCmd {
464+ LogShellCmd (cmdStrs , env )
465+ }
466+
421467 o , err := cmd .CombinedOutput ()
422468
423469 if maxDbgOutputChrs < 0 || len (o ) <= maxDbgOutputChrs {
0 commit comments