'echo "": No such file or directory" error using "exec" to pipe in PHP script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • comp.lang.tcl

    'echo "": No such file or directory" error using "exec" to pipe in PHP script

    [TCL]

    set php {<? print_r("Hello World"); ?>}
    puts $php; # PRINTS OUT <? print_r("Hello World"); ?>
    puts [exec "echo '$php' | php -q"]

    [/TCL]

    When I try this within TCL I get the following error:

    echo "": No such file or directory
    I am unable to be able to use the CLI PHP "php -r" option due to my PHP
    installations on various servers being CGI and not CLI SAPI, else, I
    would just do that, so I'm trying an alternative that is choking TCL.

    I am using a very simple example within the TCL $php variable; the
    actual contents of $php will be a bit more complex and dynamic,
    however, it's still choking on the simple PHP content.

    So how on earth do I get TCL and PHP to play nice?

    Thanx
    Phil

  • Bryan Oakley

    #2
    Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipein PHP script

    comp.lang.tcl wrote:
    [TCL]
    >
    set php {<? print_r("Hello World"); ?>}
    puts $php; # PRINTS OUT <? print_r("Hello World"); ?>
    puts [exec "echo '$php' | php -q"]
    >
    [/TCL]
    >
    When I try this within TCL I get the following error:
    >
    echo "": No such file or directory
    >
    "echo" is not a command you can exec. It is a "built-in" -- a command
    known only to the shell that implements it. Think of it more as a
    subcommand of sh/bash/ash/tcsh/etc. Much like those commands don't know
    about "proc".

    You need to understand that 'exec' simply runs a file given to it as the
    first argument. It does a couple of shortcuts such as looking for the
    file within the directories in the PATH environment variable, and will
    look for both "foo.exe" and "foo" on windows. But the fact remains, it
    is a way to spawn the execution of a file rather than a command line.

    If you're wanting to exec php and give it the contents of a variable on
    stdin, try this:

    puts [exec php << $php]

    You need to make sure that "php" is a valid command file on your
    machine, and that its location is in your PATH environment variable.

    Comment

    • Uwe Klein

      #3
      Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipein PHP script

      comp.lang.tcl wrote:
      [TCL]
      >
      set php {<? print_r("Hello World"); ?>}
      puts $php; # PRINTS OUT <? print_r("Hello World"); ?>
      puts [exec "echo '$php' | php -q"]
      puts [exec echo $php | php -q ]

      you might have even more fun with

      exec php -p <<$php
      >
      [/TCL]
      >
      When I try this within TCL I get the following error:
      >
      echo "": No such file or directory
      >
      I am unable to be able to use the CLI PHP "php -r" option due to my PHP
      installations on various servers being CGI and not CLI SAPI, else, I
      would just do that, so I'm trying an alternative that is choking TCL.
      >
      I am using a very simple example within the TCL $php variable; the
      actual contents of $php will be a bit more complex and dynamic,
      however, it's still choking on the simple PHP content.
      >
      So how on earth do I get TCL and PHP to play nice?
      >
      Thanx
      Phil
      uwe
      >

      Comment

      • comp.lang.tcl

        #4
        Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipe in PHP script


        Bryan Oakley wrote:
        comp.lang.tcl wrote:
        [TCL]

        set php {<? print_r("Hello World"); ?>}
        puts $php; # PRINTS OUT <? print_r("Hello World"); ?>
        puts [exec "echo '$php' | php -q"]

        [/TCL]

        When I try this within TCL I get the following error:

        echo "": No such file or directory
        >
        "echo" is not a command you can exec. It is a "built-in" -- a command
        known only to the shell that implements it. Think of it more as a
        subcommand of sh/bash/ash/tcsh/etc. Much like those commands don't know
        about "proc".
        >
        You need to understand that 'exec' simply runs a file given to it as the
        first argument. It does a couple of shortcuts such as looking for the
        file within the directories in the PATH environment variable, and will
        look for both "foo.exe" and "foo" on windows. But the fact remains, it
        is a way to spawn the execution of a file rather than a command line.
        >
        If you're wanting to exec php and give it the contents of a variable on
        stdin, try this:
        >
        puts [exec php << $php]
        >
        You need to make sure that "php" is a valid command file on your
        machine, and that its location is in your PATH environment variable.
        Ok this is what I did:

        [TCL]
        set contentsList [exec $valPHPPath << $php]; # $valPHPPath IS THE PATH
        TO "php"
        [/TCL]

        And here is the error message I now get:

        Status: 404 X-Powered-By: PHP/4.4.4 Content-type: text/html No input
        file specified. child process exited abnormally while executing "exec
        $valPHPPath << $php" (procedure "XML_GET_ALL_EL EMENT_ATTRS" line 36)

        I even tried a variant:

        [TCL]
        set contentsList [exec $valPHPPath << '[regsub -all {'} $php {\\'} php;
        set php]']
        [/TCL]

        And got this error message

        Status: 404 X-Powered-By: PHP/4.4.4 Content-type: text/html No input
        file specified. child process exited abnormally while executing "exec
        $valPHPPath << '[regsub -all {'} $php {\\'} php; set php]'" (procedure
        "XML_GET_ALL_EL EMENT_ATTRS" line 36)

        And even this:

        [TCL]
        set contentsList [exec $valPHPPath << '<? print_r("Hello World"); ?>']
        [/TCL]

        To no avail, getting the following error message:

        Status: 404 X-Powered-By: PHP/4.4.4 Content-type: text/html No input
        file specified. child process exited abnormally while executing "exec
        $valPHPPath << '

        I am not sure where to go going forward with this at this point, sorry,
        you may have to make it a bit more simple for me to understand how to
        make this work properly

        Phil

        Comment

        • Bryan Oakley

          #5
          Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipein PHP script

          comp.lang.tcl wrote:
          Bryan Oakley wrote:
          >
          >>comp.lang.t cl wrote:
          >>
          >>>[TCL]
          >>>
          >>>set php {<? print_r("Hello World"); ?>}
          >>>...
          >>>[/TCL]
          >>If you're wanting to exec php and give it the contents of a variable on
          >>stdin, try this:
          >>
          >>puts [exec php << $php]
          >>
          >>You need to make sure that "php" is a valid command file on your
          >>machine, and that its location is in your PATH environment variable.
          >
          >
          Ok this is what I did:
          >
          [TCL]
          set contentsList [exec $valPHPPath << $php]; # $valPHPPath IS THE PATH
          TO "php"
          [/TCL]
          >
          In the above, is $php the string you showed earlier or does it contain
          something else?
          And here is the error message I now get:
          >
          Status: 404 X-Powered-By: PHP/4.4.4 Content-type: text/html No input
          file specified. child process exited abnormally while executing "exec
          $valPHPPath << $php" (procedure "XML_GET_ALL_EL EMENT_ATTRS" line 36)
          >
          I'm not sure what the problem is, if all you say is true. When I type in
          the equivalent, I get back "Hello World":

          $ tclsh
          % set php {<? print_r("Hello World"); ?>}
          <? print_r("Hello World"); ?>
          % exec php << $php
          Hello World

          So... the only conclusion I can draw is that your php command doesn't
          work the same way as mine. That, or you're putting something different
          in $php. Unfortunately I am not able to exactly duplicate your
          environment since you're executing tcl from with a web page served by
          some tcl-enabled web server, and I don't have that web server (what web
          server is that, BTW?)

          The only thing I can suggest at this point is that the problem is no
          longer a Tcl problem but rather a php or web server problem.

          Is it possible that your php script prints to stderr instead of / in
          addition to stdout? If exec detects output on stderr it will throw an
          error unless stderr is redirected (this is all documented on the exec
          man page)

          I even tried a variant:
          >
          [TCL]
          set contentsList [exec $valPHPPath << '[regsub -all {'} $php {\\'} php;
          set php]']
          [/TCL]
          >
          Are you aware that single quotes are not a valid quoting mechanism for
          Tcl? Any time you try to use single quotes to quote something in Tcl
          you're bound to be disappointed.

          Comment

          • comp.lang.tcl

            #6
            Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipe in PHP script


            Bryan Oakley wrote:
            comp.lang.tcl wrote:
            Bryan Oakley wrote:
            >comp.lang.tc l wrote:
            >
            >>[TCL]
            >>
            >>set php {<? print_r("Hello World"); ?>}
            >>...
            >>[/TCL]
            >
            >If you're wanting to exec php and give it the contents of a variable on
            >stdin, try this:
            >
            >puts [exec php << $php]
            >
            >You need to make sure that "php" is a valid command file on your
            >machine, and that its location is in your PATH environment variable.

            Ok this is what I did:

            [TCL]
            set contentsList [exec $valPHPPath << $php]; # $valPHPPath IS THE PATH
            TO "php"
            [/TCL]
            >
            In the above, is $php the string you showed earlier or does it contain
            something else?
            >
            And here is the error message I now get:

            Status: 404 X-Powered-By: PHP/4.4.4 Content-type: text/html No input
            file specified. child process exited abnormally while executing "exec
            $valPHPPath << $php" (procedure "XML_GET_ALL_EL EMENT_ATTRS" line 36)
            >
            I'm not sure what the problem is, if all you say is true. When I type in
            the equivalent, I get back "Hello World":
            >
            $ tclsh
            % set php {<? print_r("Hello World"); ?>}
            <? print_r("Hello World"); ?>
            % exec php << $php
            Hello World
            When I went into command-line and tried it (again I'm using HP-UX
            apparently):

            set php
            <?
            error_reporting (E_ALL & ~E_NOTICE);
            $xml = preg_replace('/(>)[\\n\\r\\\s\\t]+(<)/', '$1$2',
            $argv[1]); /* STRIP OUT WHITESPACE xml_parser_set_ option() MIGHT MANGLE
            XML */
            $parser = @xml_parser_cre ate();
            @xml_parse_into _struct($parser , $xml, $xmlArray, $tags);
            @xml_parser_fre e_parser($parse r);
            for ($i = 1; $i < @sizeof($xmlArr ay) - 1; $i++) \{
            foreach ($xmlArray[$i]['attributes'] as $attr =$val)
            $tclList .= $attr . ' \{' . str_replace('\{ ', '&#123;',
            str_replace('\} ', '&#125;', $val)) . '\} '; /* ESCAPED CURLY BRACES FOR
            TCL LIST */
            \}
            echo trim($tclList);
            ?>
            % exec /usr/local/bin/php -q << $php
            <br />
            <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1
            in <b>-</bon line <b>7</b><br />
            <br />
            <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1
            in <b>-</bon line <b>10</b><br />
            child process exited abnormally
            I realize I am getting PHP errors, so at this point I don't know if
            this is a TCL problem with the way I'm creating $php, or a PHP problem
            with the way TCL handles PHP. So I believe cross-posting is essential
            for this to be solved at this point.
            >
            So... the only conclusion I can draw is that your php command doesn't
            work the same way as mine. That, or you're putting something different
            in $php. Unfortunately I am not able to exactly duplicate your
            environment since you're executing tcl from with a web page served by
            some tcl-enabled web server, and I don't have that web server (what web
            server is that, BTW?)
            Apache 2.0.53
            >
            The only thing I can suggest at this point is that the problem is no
            longer a Tcl problem but rather a php or web server problem.
            >
            Is it possible that your php script prints to stderr instead of / in
            addition to stdout? If exec detects output on stderr it will throw an
            error unless stderr is redirected (this is all documented on the exec
            man page)
            >
            >
            I even tried a variant:

            [TCL]
            set contentsList [exec $valPHPPath << '[regsub -all {'} $php {\\'} php;
            set php]']
            [/TCL]
            >
            Are you aware that single quotes are not a valid quoting mechanism for
            Tcl? Any time you try to use single quotes to quote something in Tcl
            you're bound to be disappointed.
            Yes, but I was assuming that I needed to encase $php in single quotes
            not for TCL exec but for the shell statement that is served by TCL
            exec, if that makes sense.

            Phil

            Comment

            • Bryan Oakley

              #7
              Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipein PHP script

              comp.lang.tcl wrote:
              When I went into command-line and tried it (again I'm using HP-UX
              apparently):
              >
              set php
              <?
              error_reporting (E_ALL & ~E_NOTICE);
              ...
              You are obviously paraphrasing; the above is invalid tcl and can't
              possibly be what you are actually doing or you would get different
              error messages. When you are reporting results, please try to be exact.
              Show us *precisely* what you type.

              $xml = preg_replace('/(>)[\\n\\r\\\s\\t]+(<)/', '$1$2',
              $argv[1]); /* STRIP OUT WHITESPACE xml_parser_set_ option() MIGHT MANGLE
              XML */
              $parser = @xml_parser_cre ate();
              @xml_parse_into _struct($parser , $xml, $xmlArray, $tags);
              @xml_parser_fre e_parser($parse r);
              for ($i = 1; $i < @sizeof($xmlArr ay) - 1; $i++) \{
              foreach ($xmlArray[$i]['attributes'] as $attr =$val)
              $tclList .= $attr . ' \{' . str_replace('\{ ', '&#123;',
              str_replace('\} ', '&#125;', $val)) . '\} '; /* ESCAPED CURLY BRACES FOR
              TCL LIST */
              \}
              echo trim($tclList);
              ?>
              % exec /usr/local/bin/php -q << $php
              <br />
              <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1
              in <b>-</bon line <b>7</b><br />
              <br />
              <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1
              in <b>-</bon line <b>10</b><br />
              child process exited abnormally
              >
              >
              I realize I am getting PHP errors, so at this point I don't know if
              this is a TCL problem with the way I'm creating $php, or a PHP problem
              with the way TCL handles PHP.
              What happens if you cut and paste that exact data into a file and
              execute it via php? And by "exact" I mean *exact*, minus the leading and
              trailing {} (assuming you're using {} when assigning the php script to
              the php variable).
              >>
              >>Are you aware that single quotes are not a valid quoting mechanism for
              >>Tcl? Any time you try to use single quotes to quote something in Tcl
              >>you're bound to be disappointed.
              >
              >
              Yes, but I was assuming that I needed to encase $php in single quotes
              not for TCL exec but for the shell statement that is served by TCL
              exec, if that makes sense.
              Tcl's exec doesn't have anything to do with a "shell statement". In the
              way you are using it you aren't executing a shell, not even magically
              under the covers. You're executing php directly. It is important you are
              aware of that fact.


              Comment

              • Cameron Laird

                #8
                Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipe in PHP script

                In article <1164996048.727 448.61880@f1g20 00cwa.googlegro ups.com>,
                comp.lang.tcl <phillip.s.powe ll@gmail.comwro te:

                Comment

                • comp.lang.tcl

                  #9
                  Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipe in PHP script


                  Bryan Oakley wrote:
                  comp.lang.tcl wrote:
                  When I went into command-line and tried it (again I'm using HP-UX
                  apparently):

                  set php
                  <?
                  error_reporting (E_ALL & ~E_NOTICE);
                  ...
                  >
                  You are obviously paraphrasing; the above is invalid tcl and can't
                  possibly be what you are actually doing or you would get different
                  error messages. When you are reporting results, please try to be exact.
                  Show us *precisely* what you type.
                  set php {<?
                  error_reporting (E_ALL & ~E_NOTICE);
                  $xml = preg_replace('/(>)[\\n\\r\\\s\\t]+(<)/', '$1$2',
                  $argv[1]); /* STRIP OUT WHITESPACE xml_parser_set_ option() MIGHT MANGLE
                  XML */
                  $parser = @xml_parser_cre ate();
                  @xml_parse_into _struct($parser , $xml, $xmlArray, $tags);
                  @xml_parser_fre e_parser($parse r);
                  for ($i = 1; $i < @sizeof($xmlArr ay) - 1; $i++) \{
                  foreach ($xmlArray[$i]['attributes'] as $attr =$val)
                  $tclList .= $attr . ' \{' . str_replace('\{ ', '&#123;',
                  str_replace('\} ', '&#125;', $val)) . '\} '; /* ESCAPED CURLY BRACES FOR
                  TCL LIST */
                  \}
                  echo trim($tclList);
                  ?>}

                  global valPHPPath
                  if {![info exists valPHPPath]} {
                  if {![array exists env]} { global env }
                  source cgi_globals.tcl
                  global valPHPPath
                  }
                  set contentsList [exec $valPHPPath << $php]


                  -----------
                  There you go, exactly what I typed
                  -----------

                  This is the error I get:

                  Status: 404 X-Powered-By: PHP/4.4.4 Content-type: text/html No input
                  file specified. child process exited abnormally while executing "exec
                  $valPHPPath -q << $php" (procedure "XML_GET_ALL_EL EMENT_ATTRS" line 37)


                  >
                  >
                  $xml = preg_replace('/(>)[\\n\\r\\\s\\t]+(<)/', '$1$2',
                  $argv[1]); /* STRIP OUT WHITESPACE xml_parser_set_ option() MIGHT MANGLE
                  XML */
                  $parser = @xml_parser_cre ate();
                  @xml_parse_into _struct($parser , $xml, $xmlArray, $tags);
                  @xml_parser_fre e_parser($parse r);
                  for ($i = 1; $i < @sizeof($xmlArr ay) - 1; $i++) \{
                  foreach ($xmlArray[$i]['attributes'] as $attr =$val)
                  $tclList .= $attr . ' \{' . str_replace('\{ ', '&#123;',
                  str_replace('\} ', '&#125;', $val)) . '\} '; /* ESCAPED CURLY BRACES FOR
                  TCL LIST */
                  \}
                  echo trim($tclList);
                  ?>
                  % exec /usr/local/bin/php -q << $php
                  <br />
                  <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1
                  in <b>-</bon line <b>7</b><br />
                  <br />
                  <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1
                  in <b>-</bon line <b>10</b><br />
                  child process exited abnormally
                  I realize I am getting PHP errors, so at this point I don't know if
                  this is a TCL problem with the way I'm creating $php, or a PHP problem
                  with the way TCL handles PHP.
                  >
                  What happens if you cut and paste that exact data into a file and
                  execute it via php? And by "exact" I mean *exact*, minus the leading and
                  trailing {} (assuming you're using {} when assigning the php script to
                  the php variable).
                  I get warnings on the lines where I have "\{" and "\}", but don't I
                  have to escape curly braces found within strings encased in curly
                  braces?
                  >
                  >
                  >Are you aware that single quotes are not a valid quoting mechanism for
                  >Tcl? Any time you try to use single quotes to quote something in Tcl
                  >you're bound to be disappointed.

                  Yes, but I was assuming that I needed to encase $php in single quotes
                  not for TCL exec but for the shell statement that is served by TCL
                  exec, if that makes sense.
                  >
                  Tcl's exec doesn't have anything to do with a "shell statement". In the
                  way you are using it you aren't executing a shell, not even magically
                  under the covers. You're executing php directly. It is important you are
                  aware of that fact.
                  I think I understand.. that's as far as I can go right now

                  Comment

                  • comp.lang.tcl

                    #10
                    Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipe in PHP script


                    Bryan Oakley wrote:
                    comp.lang.tcl wrote:
                    When I went into command-line and tried it (again I'm using HP-UX
                    apparently):

                    set php
                    <?
                    error_reporting (E_ALL & ~E_NOTICE);
                    ...
                    >
                    You are obviously paraphrasing; the above is invalid tcl and can't
                    possibly be what you are actually doing or you would get different
                    error messages. When you are reporting results, please try to be exact.
                    Show us *precisely* what you type.
                    Oh and I also tried this to, also to no avail:

                    % set php
                    <?
                    error_reporting (E_ALL & ~E_NOTICE);
                    $xml = preg_replace('/(>)[\n\r\\s\t]+(<)/', '$1$2',
                    $argv[1]); /* STRIP OUT WHITESPACE xml_parser_set_ option() MIGHT MANGLE
                    XML */
                    $parser = @xml_parser_cre ate();
                    @xml_parse_into _struct($parser , $xml, $xmlArray, $tags);
                    @xml_parser_fre e_parser($parse r);
                    for ($i = 1; $i < @sizeof($xmlArr ay) - 1; $i++) {
                    foreach ($xmlArray[$i]['attributes'] as $attr =$val)
                    $tclList .= $attr . ' {' . str_replace('{' , '&#123;',
                    str_replace('}' , '&#125;', $val)) . '} '; /* ESCAPED CURLY BRACES FOR
                    TCL LIST */
                    }
                    echo trim($tclList);
                    ?>
                    % exec php -q << $php
                    child process exited abnormally
                    % exec php << $php
                    X-Powered-By: PHP/4.4.4
                    Content-type: text/html

                    child process exited abnormally
                    % exec php -q << <? print_r("Hello World"); ?>
                    No input file specified.
                    child process exited abnormally
                    % exec php << <? print_r("hello world"); ?>
                    Status: 404
                    X-Powered-By: PHP/4.4.4
                    Content-type: text/html

                    No input file specified.
                    child process exited abnormally

                    >
                    >
                    $xml = preg_replace('/(>)[\\n\\r\\\s\\t]+(<)/', '$1$2',
                    $argv[1]); /* STRIP OUT WHITESPACE xml_parser_set_ option() MIGHT MANGLE
                    XML */
                    $parser = @xml_parser_cre ate();
                    @xml_parse_into _struct($parser , $xml, $xmlArray, $tags);
                    @xml_parser_fre e_parser($parse r);
                    for ($i = 1; $i < @sizeof($xmlArr ay) - 1; $i++) \{
                    foreach ($xmlArray[$i]['attributes'] as $attr =$val)
                    $tclList .= $attr . ' \{' . str_replace('\{ ', '&#123;',
                    str_replace('\} ', '&#125;', $val)) . '\} '; /* ESCAPED CURLY BRACES FOR
                    TCL LIST */
                    \}
                    echo trim($tclList);
                    ?>
                    % exec /usr/local/bin/php -q << $php
                    <br />
                    <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1
                    in <b>-</bon line <b>7</b><br />
                    <br />
                    <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1
                    in <b>-</bon line <b>10</b><br />
                    child process exited abnormally
                    I realize I am getting PHP errors, so at this point I don't know if
                    this is a TCL problem with the way I'm creating $php, or a PHP problem
                    with the way TCL handles PHP.
                    >
                    What happens if you cut and paste that exact data into a file and
                    execute it via php? And by "exact" I mean *exact*, minus the leading and
                    trailing {} (assuming you're using {} when assigning the php script to
                    the php variable).
                    >
                    >
                    >Are you aware that single quotes are not a valid quoting mechanism for
                    >Tcl? Any time you try to use single quotes to quote something in Tcl
                    >you're bound to be disappointed.

                    Yes, but I was assuming that I needed to encase $php in single quotes
                    not for TCL exec but for the shell statement that is served by TCL
                    exec, if that makes sense.
                    >
                    Tcl's exec doesn't have anything to do with a "shell statement". In the
                    way you are using it you aren't executing a shell, not even magically
                    under the covers. You're executing php directly. It is important you are
                    aware of that fact.

                    Comment

                    • Uwe Klein

                      #11
                      Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipein PHP script

                      comp.lang.tcl wrote:
                      This is the error I get:
                      >
                      Status: 404 X-Powered-By: PHP/4.4.4 Content-type: text/html No input
                      file specified. child process exited abnormally while executing "exec
                      $valPHPPath -q << $php" (procedure "XML_GET_ALL_EL EMENT_ATTRS" line 37)
                      this may be an error or just happen because the invokation of php outputs
                      something to stderr.
                      you may want to wrap the [exec ... ] into a catch statement like:

                      if {[catch {exec $valPHPPath -q << $php"} retval]} {
                      # talk about what the error was
                      puts stderr "exec with error: $retval"
                      } else {
                      # do something sensible with a successfull return.
                      }


                      and see whats happening.
                      catch is very usefull, but you may want to take some rye on the side ;-)

                      uwe

                      Comment

                      • comp.lang.tcl

                        #12
                        Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipe in PHP script


                        Uwe Klein wrote:
                        comp.lang.tcl wrote:
                        >
                        This is the error I get:

                        Status: 404 X-Powered-By: PHP/4.4.4 Content-type: text/html No input
                        file specified. child process exited abnormally while executing "exec
                        $valPHPPath -q << $php" (procedure "XML_GET_ALL_EL EMENT_ATTRS" line 37)
                        >
                        this may be an error or just happen because the invokation of php outputs
                        something to stderr.
                        you may want to wrap the [exec ... ] into a catch statement like:
                        >
                        if {[catch {exec $valPHPPath -q << $php"} retval]} {
                        # talk about what the error was
                        puts stderr "exec with error: $retval"
                        } else {
                        # do something sensible with a successfull return.
                        }
                        >
                        >
                        and see whats happening.
                        catch is very usefull, but you may want to take some rye on the side ;-)
                        >
                        uwe
                        I wish I could see what's happening, but I have no way of ever knowing
                        what's going on

                        if {[catch [exec $valPHPPath -q << $php] errMsg]} {
                        puts "!!error in exec: $errMsg!!"
                        } else {
                        puts "This is your list!"
                        return "This is your list: $errMsg"
                        }

                        produces:

                        Status: 404 X-Powered-By: PHP/4.4.4 Content-type: text/html No input
                        file specified. child process exited abnormally while executing "exec
                        $valPHPPath -q << $php" (procedure "XML_GET_ALL_EL EMENT_ATTRS" line 37)

                        It is not even performing "puts" in either case, so I am not apparently
                        even catching the error, or I have no idea what's going on!

                        Phil

                        Comment

                        • Bryan Oakley

                          #13
                          Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipein PHP script

                          comp.lang.tcl wrote:
                          Bryan Oakley wrote:
                          >>Show us *precisely* what you type.
                          >
                          >
                          set php {<?
                          error_reporting (E_ALL & ~E_NOTICE);
                          $xml = preg_replace('/(>)[\\n\\r\\\s\\t]+(<)/', '$1$2',
                          $argv[1]); /* STRIP OUT WHITESPACE xml_parser_set_ option() MIGHT MANGLE
                          XML */
                          $parser = @xml_parser_cre ate();
                          @xml_parse_into _struct($parser , $xml, $xmlArray, $tags);
                          @xml_parser_fre e_parser($parse r);
                          for ($i = 1; $i < @sizeof($xmlArr ay) - 1; $i++) \{
                          foreach ($xmlArray[$i]['attributes'] as $attr =$val)
                          $tclList .= $attr . ' \{' . str_replace('\{ ', '&#123;',
                          str_replace('\} ', '&#125;', $val)) . '\} '; /* ESCAPED CURLY BRACES FOR
                          TCL LIST */
                          \}
                          echo trim($tclList);
                          ?>}
                          >
                          global valPHPPath
                          if {![info exists valPHPPath]} {
                          if {![array exists env]} { global env }
                          source cgi_globals.tcl
                          global valPHPPath
                          }
                          set contentsList [exec $valPHPPath << $php]
                          >
                          >
                          -----------
                          There you go, exactly what I typed
                          -----------
                          >
                          This is the error I get:
                          >
                          Status: 404 X-Powered-By: PHP/4.4.4 Content-type: text/html No input
                          file specified. child process exited abnormally while executing "exec
                          $valPHPPath -q << $php" (procedure "XML_GET_ALL_EL EMENT_ATTRS" line 37)
                          Strip out all the Tcl. All of it. Every last byte. Put the php into a
                          file. Then, from a command line type "php /your/file.php"

                          You will get the exact same error. The bug is in php, of which I know
                          nothing about. What I do know is that the problem isn't Tcl.

                          Comment

                          • comp.lang.tcl

                            #14
                            Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipe in PHP script


                            Bryan Oakley wrote:
                            comp.lang.tcl wrote:
                            Bryan Oakley wrote:
                            >Show us *precisely* what you type.

                            set php {<?
                            error_reporting (E_ALL & ~E_NOTICE);
                            $xml = preg_replace('/(>)[\\n\\r\\\s\\t]+(<)/', '$1$2',
                            $argv[1]); /* STRIP OUT WHITESPACE xml_parser_set_ option() MIGHT MANGLE
                            XML */
                            $parser = @xml_parser_cre ate();
                            @xml_parse_into _struct($parser , $xml, $xmlArray, $tags);
                            @xml_parser_fre e_parser($parse r);
                            for ($i = 1; $i < @sizeof($xmlArr ay) - 1; $i++) \{
                            foreach ($xmlArray[$i]['attributes'] as $attr =$val)
                            $tclList .= $attr . ' \{' . str_replace('\{ ', '&#123;',
                            str_replace('\} ', '&#125;', $val)) . '\} '; /* ESCAPED CURLY BRACES FOR
                            TCL LIST */
                            \}
                            echo trim($tclList);
                            ?>}

                            global valPHPPath
                            if {![info exists valPHPPath]} {
                            if {![array exists env]} { global env }
                            source cgi_globals.tcl
                            global valPHPPath
                            }
                            set contentsList [exec $valPHPPath << $php]


                            -----------
                            There you go, exactly what I typed
                            -----------

                            This is the error I get:

                            Status: 404 X-Powered-By: PHP/4.4.4 Content-type: text/html No input
                            file specified. child process exited abnormally while executing "exec
                            $valPHPPath -q << $php" (procedure "XML_GET_ALL_EL EMENT_ATTRS" line 37)
                            >
                            Strip out all the Tcl. All of it. Every last byte. Put the php into a
                            file. Then, from a command line type "php /your/file.php"
                            >
                            You will get the exact same error. The bug is in php, of which I know
                            nothing about. What I do know is that the problem isn't Tcl.
                            No, sorry I get no error whatsoever, in fact, I get nothing. It's not
                            a PHP syntax or evaluation error, it's just that apparently it seems
                            $argv does not exist because it was never set with any values, so
                            putting it into a PHP file is ultimately meaningless because I can't
                            get the XML contents into the PHP file even if it were separate.

                            So again, at this point, you're right, this is not a TCL issue and
                            needs to be moved to a PHP issue.

                            Phil

                            Comment

                            • Bryan Oakley

                              #15
                              Re: 'echo &quot;&quot; : No such file or directory&quot; error using &quot;exec&quot ; to pipein PHP script

                              comp.lang.tcl wrote:
                              Bryan Oakley wrote:
                              >
                              >>comp.lang.t cl wrote:
                              >>
                              >>>Bryan Oakley wrote:
                              >>>
                              >>>>Show us *precisely* what you type.
                              >>>
                              >>>
                              >>>set php {<?
                              >> error_reporting (E_ALL & ~E_NOTICE);
                              >> $xml = preg_replace('/(>)[\\n\\r\\\s\\t]+(<)/', '$1$2',
                              >>>$argv[1]); /* STRIP OUT WHITESPACE xml_parser_set_ option() MIGHT MANGLE
                              >>>XML */
                              >> $parser = @xml_parser_cre ate();
                              >> @xml_parse_into _struct($parser , $xml, $xmlArray, $tags);
                              >> @xml_parser_fre e_parser($parse r);
                              >> for ($i = 1; $i < @sizeof($xmlArr ay) - 1; $i++) \{
                              >> foreach ($xmlArray[$i]['attributes'] as $attr =$val)
                              >> $tclList .= $attr . ' \{' . str_replace('\{ ', '&#123;',
                              >>>str_replace( '\}', '&#125;', $val)) . '\} '; /* ESCAPED CURLY BRACES FOR
                              >>>TCL LIST */
                              >> \}
                              >> echo trim($tclList);
                              >> ?>}
                              >>>
                              >>global valPHPPath
                              >>if {![info exists valPHPPath]} {
                              >> if {![array exists env]} { global env }
                              >> source cgi_globals.tcl
                              >> global valPHPPath
                              >>}
                              >>set contentsList [exec $valPHPPath << $php]
                              >>>
                              >>>
                              >>>-----------
                              >>>There you go, exactly what I typed
                              >>>-----------
                              >>>
                              >>>This is the error I get:
                              >>>
                              >>>Status: 404 X-Powered-By: PHP/4.4.4 Content-type: text/html No input
                              >>>file specified. child process exited abnormally while executing "exec
                              >>>$valPHPPat h -q << $php" (procedure "XML_GET_ALL_EL EMENT_ATTRS" line 37)
                              >>
                              >>Strip out all the Tcl. All of it. Every last byte. Put the php into a
                              >>file. Then, from a command line type "php /your/file.php"
                              >>
                              >>You will get the exact same error. The bug is in php, of which I know
                              >>nothing about. What I do know is that the problem isn't Tcl.
                              >
                              >
                              No, sorry I get no error whatsoever, in fact, I get nothing.
                              You are correct. My bad. I was getting this, which is the same error
                              you were earlier reporting:

                              Warning: Unexpected character in input: '\' (ASCII=92) state=1 in
                              /private/tmp/error.php on line 9

                              Warning: Unexpected character in input: '\' (ASCII=92) state=1 in
                              /private/tmp/error.php on line 14

                              .... but that was because the php had two lines with extra backslashes,
                              that were in to escape the curly braces due to the fact it was defined
                              in Tcl. My mistake. When I took those out in the file-based version of
                              the php code, it all worked fine (and by that I mean, I get no php errors).
                              It's not
                              a PHP syntax or evaluation error, it's just that apparently it seems
                              $argv does not exist because it was never set with any values,
                              That's likely also true. Unless you give it a filename as an argument
                              you won't have a argv[1].
                              so
                              putting it into a PHP file is ultimately meaningless because I can't
                              get the XML contents into the PHP file even if it were separate.
                              The exercise of putting it in a file is just to illustrate that the php
                              has errors in it, it has nothing to do with Tcl. If you can create a
                              working block of php you can call from the command line, you can
                              certainly execute it from tcl using the "exec php << $php" trick.

                              The first trick, then, is to figure out the PHP problems. Then take the
                              working PHP and execute it via Tcl. No sense fighting two battles at once.

                              Comment

                              Working...