Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


ZSHOW output

  • Does ZSHOW cause a buffer flush (equivalent to "w !") when called and redirected to a global? I have noticed some circumstances when calling 'ZSHOW "*":^myvar' that a buffer flush appears to happen. In a web browser context this can be somewhat disruptive, in that it can cause the server to see an additional linefeed ($c(10)).


    • Dennis,

      You say the buffer flush is noticed in SOME circumstances. Does that mean the ZSHOW command works as you expect some times and does not at other times? It would really help us analyze the issue if you can give us a simple test case that reproduces this (even if it happens only once in multiple test runs).


      • Narayanan,

        I had a  great test case all written up at the time I posted this, but I'm not sure what I did with it. Anyway, I'll try again. If I have a shell script configured as a CGI script for Apache, the shell script runs the M routine ^cgi, and ^cgi is as follows, I get an extra $c(10) output (which displays as a blank line in the output, and which results in invalid XML).

        cgi ; simple CGI output
        w "Content-type:text/xml",$c(10,10)
        zsh "*":^test
        w "<?xml version=""1.0"" ?>",!

        In fact, if I remove one of the $c(10)s above, this code correctly supplies the two linefeeds that Apache expects. If I subsequently comment out the ZSH, Apache complains of invalid headers.

        I notice too that this command prints as expected:
          GTM> w "a" zsh "*":^test w "b",!


        • Bob Isch
          Bob Isch


          - I assume that removing the "zsh..." from your example makes it "work"?

          - What version of GT.M are you using?

          Some versions have issues with $X in various situations.  For example, the behavior you are seeing could be simulated by something like:

          GTM> u "":(width=30:wrap) w "Content-type:text/xml",$c(10,10) s $x=99 w "abc",!

          Meaning that the extra $c(10) is not actually generated by the zshow but by the 'w "abc"' when GT.M decides it has to wrap to a new line.  Try:

            s $x=0 zshow "*":^test s $x=0

          in your example and see if that "fixes" the problem.  If it does then perhaps zshow is updating the value of $x for the wrong "device".  You could also try opening your socket devices with :nowrap

          Also, FWIW - I tend to:

          - append $c(13,10) (CR/LF) to the end of each head and content line
          - Not use ! except at the very end (right before closing the connection)

          I am not sure if that is all "proper" though...

          Best of luck,