|
Posted by Ralf Fassel on 11/22/05 15:42
* "comp.lang.tcl" <phillip.s.powell@gmail.com>
| 4) If you just hit the carriage return, it throws an error message "You
| must enter..." and dies
--<snip-snip>--
| However, when the same PHP script is now being accessed by the TCL
| script, it does 1), you do 2), 3) occurs, but if you do 4), instead
| of correctly throwing an error message and dying, it just keeps
| going and lets you enter more "nonentities".
TCL needs some way of knowing whether the PHP script was successful or
not. If the PHP script always exits with status 0 even if no valid
input was given, then TCL needs to check the output of the script.
Here you have the problem that on the one hand, the user needs to see
the prompt (redirect PHP stdout), on the other hand TCLs needs to see
the error message.
If you're lucky, you can change the PHP script to exit non-zero in
case of invalid input. Then the 'catch' in TCL will trigger.
If you're not *that* lucky, but still *somewhat* lucky, the "You must
enter..." message from the PHP script goes to stderr. In that case
just don't redirect stderr when exec'ing the PHP script. Then the
'catch' in TCL will trigger, since anything on stderr of a subprocess
is considered an error in TCL.
if {[catch {exec php -q $root >@stdout} err]} {
puts "error while calling PHP:"
puts "errorCode $::errorCode"
puts "message: $err"
}
If the 'error' message of PHP also goes to stdout, you will have to
use some other means (expect comes to my mind then), since then you
will need to separate the prompt from the rest of the output.
HTH & good luck!
R'
Navigation:
[Reply to this message]
|