ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

PHP generated spool file line breaks

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP generated spool file line breaks

    We've started using a lot more PHP to get some modern interfaces to some out AS/400 business logic.

    While doing this, I wrote a small program in PHP to look for field/variable names in the PHP code, so that if a Physical file changes not only should we do a find string to search through PRG code, but also call a CL and search through the PHP.

    I would like to use the echo or print command to write a "report" like spool file to a queue.

    Adding a <br /> doesn't work. Adding a \n doesn't seem to affect it.

    Does anyone know how to get a line break to translate from PHP to spool file?

    Thanks-

  • #2
    Re: PHP generated spool file line breaks

    How are you writing to a spooled file from PHP? I wasn't aware that PHP even had the concept of spooled files. (Which are really an IBM i concept, on pretty much all other platforms printouts are just normal files like everything else. And since the PHP we use on IBM i is written and compiled for AIX, I'm kinda surprised that it'd even have the concept of spooled files.)

    It's hard to tell you the exact mechanism of generating a line break in a spooled file if we don't even know how you're generating the spooled file to begin with.

    <br /> is HTML -- so that seems like a strange thing to try, unless you've somehow taught the system to understand HTML files as spooled files?! (Or maybe I'm just completely lost.)

    Comment


    • #3
      Re: PHP generated spool file line breaks

      I run a lot of PHP scripts through QP2SHELL, using the PHP-CLI interface and a PHP file on the IFS under the Zend folder structures.

      I've found that any of the output generated from calling the PHP script ends up an an outq in the form of a spooled file for the user who is logged in, resulting in errors printing on their default printer.

      If you wrap the QP2SHELL call with a CHGJOB OUTQ(xxxx) command you can at least while the job is running direct all of the output that the php script is generating to a specific que.

      The issue I am running into is that the output can sometimes be wider than 80 characters (or perhaps I wanted to print wider).

      I could definitely just email the person the results and keep it out of a spool file, but I thought it would be nice to have a report a lot like what you could get with the standard search utility in your outq.

      <br /> is HTML -- so that seems like a strange thing to try, unless you've somehow taught the system to understand HTML files as spooled files?! (Or maybe I'm just completely lost.)
      It's interesting though, I don't physically see a "<br />" in the output. So either the PHP-CLI is doing some translation or the the 400 is doing it.
      Last edited by Adein; June 16, 2014, 07:43 AM.

      Comment


      • #4
        Re: PHP generated spool file line breaks

        Oh, so your PHP script isn't generating a spooled file. You are running it in a PASE job that has no interactive I/O, and the operating system is redirecting to a spooled file because it doesn't know what else to do with it.

        I'm not a big fan of using QP2SHELL because, unless you connect pipes to it, it'll try to write it's output to the ILE stdio streams, which are not threadsafe, so if you run a multi-threaded job in PASE, you can end up with a mess here. The right way to use QP2SHELL, of course, is to spawn a background job that calls QP2SHELL, and then connect pipes to that background job so you can write your own code to receive the data. But, for most progammers, this is rather complicated when they just want to run a simple PASE command, so they don't do it (And so end up with ILE stdio and it's problems.) A better solution is to use QShell (STRQSH command) instead of QP2SHELL, which takes care of these stdio streams automatically.

        But, anyway... If your goal is to generate a report, maybe a better solution is to use the 'pr' and 'Rfile' utilities. The Rfile command can be used to redirect the output from PHP directly to a spooled file (without relying on the default behavior of QP2SHELL in a non-interactive environment.) The 'pr' utility can be used to paginate the output for you, and add some stuff to the headings, etc if that is desired.

        Comment


        • #5
          Re: PHP generated spool file line breaks

          I changed over to the QShell to get the STD connectors in place, which helped.

          Then I used PHP's printf function with "%s\r\n" as the format and was able to achieve a spool file with line returns.

          Thanks for the help Scott.

          Comment


          • #6
            Re: PHP generated spool file line breaks

            If you use php's printf with just \n, (or use 'echo' for that matter) it doesn't result in a line break? That seems very strange to me. Ending a line with a linefeed (without the \r) is the norm in Unix shell environments (like QShell) so I don't see why you'd need the \r

            Comment

            Working...
            X