+proc gas_host_run { cmd redir } {
+ verbose "Executing $cmd $redir"
+ set return_contents_of ""
+ if [regexp ">& */dev/null" $redir] then {
+ set output_file ""
+ set command "$cmd $redir"
+ } elseif [regexp "> */dev/null" $redir] then {
+ set output_file ""
+ set command "$cmd 2>gas.stderr"
+ set return_contents_of "gas.stderr"
+ } elseif [regexp ">&.*" $redir] then {
+ # See PR 5322 for why the following line is used.
+ regsub ">&" $redir "" output_file
+ set command "$cmd 2>&1"
+ } elseif [regexp "2>.*" $redir] then {
+ set output_file "gas.out"
+ set command "$cmd $redir"
+ set return_contents_of "gas.out"
+ } elseif [regexp ">.*" $redir] then {
+ set output_file ""
+ set command "$cmd $redir 2>gas.stderr"
+ set return_contents_of "gas.stderr"
+ } elseif { "$redir" == "" } then {
+ set output_file "gas.out"
+ set command "$cmd 2>&1"
+ set return_contents_of "gas.out"
+ } else {
+ fail "gas_host_run: unknown form of redirection string"
+ }
+
+ set status [remote_exec host [concat sh -c [list $command]] "" "/dev/null" "$output_file"]
+ set to_return ""
+ if { "$return_contents_of" != "" } then {
+ remote_upload host "$return_contents_of"
+ set to_return [file_contents "$return_contents_of"]
+ regsub "\n$" $to_return "" to_return
+ }
+
+ if { [lindex $status 0] == 0 && "$output_file" != ""
+ && "$output_file" != "$return_contents_of" } then {
+ remote_upload host "$output_file"
+ }
+
+ return [list [lindex $status 0] "$to_return"]
+}
+