473,395 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

'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

Dec 1 '06 #1
21 7781
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.
Dec 1 '06 #2
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
>
Dec 1 '06 #3

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_ELEMENT_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_ELEMENT_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

Dec 1 '06 #4
comp.lang.tcl wrote:
Bryan Oakley wrote:
>>comp.lang.tcl 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_ELEMENT_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.
Dec 1 '06 #5

Bryan Oakley wrote:
comp.lang.tcl wrote:
Bryan Oakley wrote:
>comp.lang.tcl 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_ELEMENT_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_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free_parser($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) \{
foreach ($xmlArray[$i]['attributes'] as $attr =$val)
$tclList .= $attr . ' \{' . str_replace('\{', '{',
str_replace('\}', '}', $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

Dec 1 '06 #6
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_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free_parser($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) \{
foreach ($xmlArray[$i]['attributes'] as $attr =$val)
$tclList .= $attr . ' \{' . str_replace('\{', '{',
str_replace('\}', '}', $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.
Dec 1 '06 #7
In article <11*********************@f1g2000cwa.googlegroups.c om>,
comp.lang.tcl <ph**************@gmail.comwrote:
Dec 1 '06 #8

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_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free_parser($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) \{
foreach ($xmlArray[$i]['attributes'] as $attr =$val)
$tclList .= $attr . ' \{' . str_replace('\{', '{',
str_replace('\}', '}', $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_ELEMENT_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_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free_parser($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) \{
foreach ($xmlArray[$i]['attributes'] as $attr =$val)
$tclList .= $attr . ' \{' . str_replace('\{', '{',
str_replace('\}', '}', $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

Dec 1 '06 #9

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_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free_parser($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) {
foreach ($xmlArray[$i]['attributes'] as $attr =$val)
$tclList .= $attr . ' {' . str_replace('{', '{',
str_replace('}', '}', $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_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free_parser($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) \{
foreach ($xmlArray[$i]['attributes'] as $attr =$val)
$tclList .= $attr . ' \{' . str_replace('\{', '{',
str_replace('\}', '}', $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.
Dec 1 '06 #10
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_ELEMENT_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
Dec 1 '06 #11

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_ELEMENT_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_ELEMENT_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

Dec 1 '06 #12
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_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free_parser($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) \{
foreach ($xmlArray[$i]['attributes'] as $attr =$val)
$tclList .= $attr . ' \{' . str_replace('\{', '{',
str_replace('\}', '}', $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_ELEMENT_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.
Dec 1 '06 #13

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_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free_parser($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) \{
foreach ($xmlArray[$i]['attributes'] as $attr =$val)
$tclList .= $attr . ' \{' . str_replace('\{', '{',
str_replace('\}', '}', $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_ELEMENT_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

Dec 1 '06 #14
comp.lang.tcl wrote:
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_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free_parser($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) \{
foreach ($xmlArray[$i]['attributes'] as $attr =$val)
$tclList .= $attr . ' \{' . str_replace('\{', '{',
str_replace('\}', '}', $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_ELEMENT_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.
Dec 1 '06 #15

Bryan Oakley wrote:
comp.lang.tcl wrote:
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_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free_parser($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) \{
foreach ($xmlArray[$i]['attributes'] as $attr =$val)
$tclList .= $attr . ' \{' . str_replace('\{', '{',
str_replace('\}', '}', $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_ELEMENT_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].
Ok an update:

My TCL code has been simplified to this:

set contents {<?xml version="1.0" encoding="utf-8" ?><blah><foo
id="1"></foo></blah>}
if {[catch [exec $valPHPPath -q /home/ppowell/web/blah.php <<
$contents] errMsg]} {
puts "!!error in exec: $errMsg!!"
} else {
puts "This is your list!"
Where I put all of the contents of [set php] into "blah.php" and
calling that instead.

Well, to no avail:

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 /home/ppowell/web/blah.php << $contents" (procedure
"XML_GET_ALL_ELEMENT_ATTRS" line 39)

When I call it via command-line:

php -q /home/ppowell/web/blah.php << '<?xml version="1.0"
encoding="utf-8" ?><blah><foo id="1"></foo></blah>'

This happens:

/users/ppowell -->php -q /home/ppowell/web/blah.php << '<?xml
version="1.0" encoding="utf-8" ?><blah><foo id="1"></foo></blah>'
>
[and it just sits there for input until I hit CTRL-C]
>
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.
working PHP and execute it via Tcl. No sense fighting two battles at once.
Dec 1 '06 #16
comp.lang.tcl wrote:
When I call it via command-line:

php -q /home/ppowell/web/blah.php << '<?xml version="1.0"
encoding="utf-8" ?><blah><foo id="1"></foo></blah>'

This happens:

/users/ppowell -->php -q /home/ppowell/web/blah.php << '<?xml
version="1.0" encoding="utf-8" ?><blah><foo id="1"></foo></blah>'

[and it just sits there for input until I hit CTRL-C]
'<<' has a different behavior in a shell than it does in Tcl. You can't
use them the same way.

Using '<<' from a bash shell is what is called a "here document". Here's
one description:

http://www.faqs.org/docs/bashman/bashref_42.html#SEC42
Dec 1 '06 #17

Bryan Oakley wrote:
comp.lang.tcl wrote:
When I call it via command-line:

php -q /home/ppowell/web/blah.php << '<?xml version="1.0"
encoding="utf-8" ?><blah><foo id="1"></foo></blah>'

This happens:

/users/ppowell -->php -q /home/ppowell/web/blah.php << '<?xml
version="1.0" encoding="utf-8" ?><blah><foo id="1"></foo></blah>'

[and it just sits there for input until I hit CTRL-C]

'<<' has a different behavior in a shell than it does in Tcl. You can't
use them the same way.

Using '<<' from a bash shell is what is called a "here document". Here's
one description:

http://www.faqs.org/docs/bashman/bashref_42.html#SEC42
Ok an update:

I fixed the PHP script (you were right, there were syntax errors after
all, but I was unable to detect them):

set php {<?
error_reporting(E_ALL & ~E_NOTICE);
require_once('functions.inc.php');
$xml = preg_replace('/(>)[\n\r\\s\t]+(<)/', '$1$2',
@file_get_contents('php://stdin'));
$parser = @xml_parser_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) {
foreach ($xmlArray[$i]['attributes'] as $attr =$val) {
foreach (array(&$attr, &$val) as $field) {
$field = str_replace('{', '{', str_replace('}',
'}', $field));
$tclList .= (preg_match('/[\s\t]+/', $field)) ? '{' .
$field . '} ' : "$field ";
}
}
}
echo trim($tclList);
?}

global valPHPPath
if {![info exists valPHPPath]} {
if {![array exists env]} { global env }
source cgi_globals.tcl
global valPHPPath
}
if {[catch [exec $valPHPPath -q /home/ppowell/web/blah.php <<
$contents] result]} {
puts stderr "error involving PHP execution: $result"
exit 2;
} else {
return $result
}

Produces the same error and apparently hangs up when it tries to read
from stdin (is there a stdin size limit?), so it is no longer a TCL
problem at this point

Phil

Dec 2 '06 #18
"comp.lang.tcl" <ph**************@gmail.comwrote:
Uwe Klein wrote:
you may want to wrap the [exec ... ] into a catch statement like:

if {[catch {exec $valPHPPath -q << $php"} retval]} {
...

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]} {
...
Look closely at the difference between what Uwe suggested and what you
actually did. The [catch] command expects a script; you instead gave it
the results of executing the [exec] command.
Dec 2 '06 #19

Alan Anderson wrote:
"comp.lang.tcl" <ph**************@gmail.comwrote:
Uwe Klein wrote:
you may want to wrap the [exec ... ] into a catch statement like:
>
if {[catch {exec $valPHPPath -q << $php"} retval]} {
...
>
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]} {
...

Look closely at the difference between what Uwe suggested and what you
actually did. The [catch] command expects a script; you instead gave it
the results of executing the [exec] command.
I got to the point where the PHP script that the Tcl script is calling
is somewhat stable (provided you have very tiny inputted data!), I
guess I just won't understand how to look at what Uwe did and what I
did and see the difference as your explanation doesn't make sense
either, sorry.

Phil

Dec 2 '06 #20
I've broken this post into small, bite-sized sections. I hope that
helps compensate for how long it is.

"comp.lang.tcl" <ph**************@gmail.comwrote:
I got to the point where the PHP script that the Tcl script is calling
is somewhat stable (provided you have very tiny inputted data!), I
guess I just won't understand how to look at what Uwe did and what I
did and see the difference as your explanation doesn't make sense
either, sorry.
Uwe Klein's suggestion:
if {[catch {exec $valPHPPath -q << $php} retval]} {...}
Phillip Powell's version:
if {[catch [exec $valPHPPath -q << $php] errMsg]} {...}
Do you see the difference between these two lines? Not the obvious
retval vs. errMsg names, but the {} vs. [] characters surrounding the
exec command.

*** ***

You're coming very close to fumbling blindly around in frustration,
trying to find exactly the combination of chicken entrails and mouth
position that will yield the results you want. If you instead take a
step back and spend just a little time getting a handle on the simple
syntax of Tcl, I think you'll find the time spent will pay off manyfold.

Look at this web page: http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm

It's only eleven rules. (The imminent twelfth rule is simple, but not
important at the moment.)

*** ***

Once you grasp what those " and { and $ and [ characters are actually
doing, you'll be freer to take a look at the commands you're using, and
find out what arguments they expect to receive.

For example, [exec]: http://www.tcl.tk/man/tcl/exec.htm

It wants to see a list of words. The first word in that list is the
command to be executed (sometimes preceded by an optional switch); the
rest of the words are passed to that command as parameters, with some
exceptional cases like "|" and "<<" treated, err, exceptionally.

Another example, [catch]: http://www.tcl.tk/man/tcl/catch.htm

It wants to see a pair of words. The first one is a script which it
evaluates; the second is the name of a variable in which to store the
results of evaluating the script.

*** ***

And use the Tcler's Wiki: http://wiki.tcl.tk/

It has pages giving simple and clear examples of just about any command
you want to use. In most cases, it also gives good advice on *why* you
should follow those examples.
Dec 2 '06 #21
In article <11*********************@j44g2000cwa.googlegroups. com>,
comp.lang.tcl <ph**************@gmail.comwrote:
Dec 2 '06 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Thomas Brathans | last post by:
Hi, when I try to execute the obove mentioned to synchronise the servertime by a php-script, it doesn't work. Other shell-commands work fine. Executing ntpdate <server> directly in the shell...
5
by: Toby Donaldson | last post by:
Hi all, I'm designing an educational application that will run Python code and check the output against a pre-define answer. I want to use the "exec" statement to run the code, but I don't know...
2
by: tedsuzman | last post by:
----- def f(): ret = 2 exec "ret += 10" return ret print f() ----- The above prints '12', as expected. However,
1
by: Ted | last post by:
-------- def f(): ret = 2 exec "ret += 10" return ret print f() -------- The above example prints '12'. However, the following example prints
1
by: kurt.krueckeberg | last post by:
The second line of this script <?php // current directory echo getcwd() . "<br />"; print ( exec("ls *.*") ); ?> should display the names of the four files (it does in an ssh session) which...
2
by: Marty Meyers | last post by:
I have the following line in a php file: $msg= exec("perl $scriptPath/insert.pl $d $u $t 2>&1", $returnVal); Can someone explain the "2>&1" argument? Second problem, this same line of code...
4
by: Tom | last post by:
I have a script which allows a user to upload a file. The script does some filename editing, mimetype checking, etc., and it's then supposed to send the file to a remote server, without any...
2
by: xml0x1a | last post by:
How do I use exec? Python 2.4.3 ---- from math import * G = 1 def d(): L = 1 exec "def f(x): return L + log(G) " in globals(), locals() f(1)
2
by: shathil | last post by:
#!/bin/bash cat /var/backup/192.168.4.3/dirnum.prn | awk '{print $1}' if i put above script can read the file. #!/bin/bash file1=/var/backup/192.168.4.3/dirnum.prn exec <$file1 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.