|
Posted by Bryan Oakley on 11/25/06 18:42
comp.lang.tcl wrote:
> Bryan Oakley wrote:
>
>>comp.lang.tcl wrote:
>>
>>> set cannotRunPHP [catch {exec "echo '$php' | php" >@stdout
>>>2>&stderr} errorMsg]
>>
>>You need to re-read the man page on exec. The first argument to exec is
>>a filename that will be exec'd; it is not a command line. If you want to
>> run a command line you should exec a command line processor (/bin/sh,
>>command.com, whatever).
>>
>>Since "php" is what you want to exec, and $php is what you want to send
>>to its stdin, use "<<" (documented on the exec man page):
>>
>> if {[catch {exec php << $php} result]} {
>> puts "error exec'ing php: $resulut"
>> } else {
>> puts "php result: $result"
>> }
>
>
>
> Now I get this error:
>
> couldn't execute "php": no such file or directory
>
> When I try this:
>
> [TCL]
> set cannotRunPHP [catch {exec exec php << $php >@stdout 2>&stderr}
> errorMsg]
> if {$cannotRunPHP} {
> puts $errorMsg
> return {}
> } else {
> if {![IS_LIST $contentsList]} { set contentsList [split
> $contentsList] }
> if {[llength $contentsList] == 0} { lappend contentsList {?} }
> return [lrange $contentsList [expr {[lsearch -exact $contentsList
> "?"] + 1}] end]
> }
>
> [/TCL]
>
> Wow this should only take an hour, it's taken 3 days so far!
When you are learning a new language, it always takes much longer to
solve problems. And in your case I'm afraid, you aren't taking much time
to actually learn the language which is compounding the problem.
The answer to your current problem is well documented in the exec man
page, and on the exec pages on the tcler's wiki. The problem you are
encountering is very simple: you are telling it to execute "php" but tcl
can't find "php". The short answer is, you either have to explicitly
tell the exec command which *file* to execute (eg: exec
/usr/local/bin/php), or you have to make sure that the file you tell it
exists somewhere within a directory defined in your PATH environment
variable.
Phil, I'm sorry you're having so many problems. You are correct that
this probably should have taken only an hour or two for a seasoned
programmer, but you are not a seasoned programmer and properly parsing
XML is, generally speaking, a Hard Problem. At least, it's hard when you
choose to not use proper XML parsing solutions and instead rely on a
series of text transformations.
Tcl is a very powerful language, but it doesn't have built-in facilities
to parse XML. This is not a weakness of Tcl, it's just the way it is.
The beauty of Tcl is, people can write extensions to the language to do
just about anything, including parsing XML. Unfortunately, you are
choosing not to take the time to learn how to use them.
I'll again recommend trying the xml2list function documented here:
http://mini.net/tcl/3919. I'm guessing that will work good enough for
you. Fortunately, it appears you're working on a simply hobby
application rather than a commercial application so we don't have to
worry so much about robustness.
[Back to original message]
|