saving subprocess output in local copy, tee, and exit codes

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

saving subprocess output in local copy, tee, and exit codes

René J.V. Bertin
Hi,

As you may know there is a feature among my (partly pending) cmake-1.1 PortGroup that allows port developers to obtain a local copy of the cmake invocation in the port's work directory. I'm trying to save cmake's output too because the copy in the port logfile has the habit of being gone just when you need it. (Even the regular upgrade process overwrites the logfile during the actual install/upgrade step.)

The most straightforward approach is this:

{{{
proc cmake.save_configure_cmd {{save_log_too ""}} {
    if {${save_log_too} ne ""} {
        pre-configure {
            configure.post_args-append "| tee ${workpath}/.macports.${subport}.configure.log"
            ui_debug "cmake.save_configure_cmd set configure.post_args to \"${configure.post_args}\""
        }
    }
    post-configure {
        if {![catch {set fd [open "${workpath}/.macports.${subport}.configure.cmd" "w"]} err]} {
# etc
}}}

That works but has a side-effect when cmake fails and returns an error that surprised me (being a *csh user).
I deduce that sh (and thus the regular system()(2) call?) return the exit code of the last command to the caller, in this case `tee`, instead of some logical combination of all exit codes of processes on the pipeline.

Is there a clever trick around this?

Thanks,
René
Reply | Threaded
Open this post in threaded view
|

Re: saving subprocess output in local copy, tee, and exit codes

René J.V. Bertin
A bit to my surprise this works with the sort of complex cmake commandlines I
get in my KF5 ports:

{{{
proc cmake.save_configure_cmd {{save_log_too ""}} {
    if {${save_log_too} ne ""} {
        pre-configure {
            configure.pre_args-prepend "-cf '${configure.cmd} "
            configure.post_args-append "|& tee ${workpath}/.macports.
${subport}.configure.log'"
            configure.cmd "/bin/csh"
            ui_debug "configure command set to `${configure.cmd}
${configure.pre_args} ${configure.args} ${configure.post_args}`"
        }
    }
# etc
}}}

R