Results 1 to 5 of 5

Thread: redirect my own output

  1. #1
    Join Date
    Jun 2008
    Location
    As. - Paraguay - GMT -4
    Posts
    95

    Default redirect my own output

    hello.

    I wonder how can I redirect my own output to a single variable using php.

    I want to change my stdout for another descriptor. My script runs in both web and shell environment so I need to change the scape characters '\n' of the console to <br> for the web version using something like nl2br() function when I explicitly want to flush that variable and display its content.

    I know that there is another way such use a custom function (that knows where is running the script) instead the natively implemented echo() function but with this, the code will look creepy and ugly.

    Gracias

  2. #2
    Jared Jennings NNTP User

    Default Re: redirect my own output

    castord said on 7/23/2008,

    >I want to change my stdout for another descriptor. My script runs in
    >both web and shell environment so I need to change the scape characters
    >'\n' of the console to <br> for the web version using something like
    >nl2br() function when I explicitly want to flush that variable and
    >display its content.
    >
    >I know that there is another way such use a custom function (that knows
    >where is running the script) instead the natively implemented echo()
    >function but with this, the code will look creepy and ugly.


    So basically a logger function, but you don't want to log to a file, but
    to stdout.

    --
    Jared Jennings - Data Technique, Inc.
    Novell Support Forums Sysop
    My Blog and Wiki with Tips, Tricks, and Tutorials
    http://jaredjennings.org

  3. #3
    Join Date
    Jun 2008
    Location
    As. - Paraguay - GMT -4
    Posts
    95

    Default Re: redirect my own output

    That's right.
    I already use a solution that I didn't like much, but seems to work. Instead echo() I wrote my own echo function which writes \n on shell environment and <br> in web.
    I still looking for the answer and the correct way to do that.

  4. #4
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: redirect my own output

    Strange that you use a PHP script for two purposes when one requires HTML and the other plain text.

    However if you use a templating system like Smarty, you can generate different output formats depending on which template you use. E.g.

    Code:
    $template = new Smarty();
    $template->assign('var', $somevar);
    ...
    if ($toterminal)
      $template->display('terminal.tpl');
    else
      $template->display('browser.tpl');

  5. #5
    Join Date
    Jun 2008
    Location
    As. - Paraguay - GMT -4
    Posts
    95

    Default Re: redirect my own output

    Strange that you use a PHP script for two purposes when one requires HTML and the other plain text.
    Actually the script shouldn't display any info but for debug purposes it was necessary. Sometimes I need to call it from a web browser and sometimes from a shell console.
    This script is executed every five minutes, reads a db2 table, does some math operations and then stores the result in another table of another db2 database. The script is running in a IBM AS400 .
    Is very hard to get use to this kind of OS when you have used Linux.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •