|
Posted by Ralf Fassel on 11/03/69 11:32
* "comp.lang.tcl" <phillip.s.powell@gmail.com>
| For some reason that I never understood, leaving off "eval" on TCL
| exec commands insured that the file included within eval "exec php
| -q [myfile]" would never be run unless I added eval. No explanation
| at all.
You do not want double quotes there, use
catch {exec php -q myfile}
This will call the command 'exec' with 'php' as first argument, '-p'
as second and 'myfile' as third argument.
If you use
catch {"exec php -q myfile"}
TCL will try to call a 4-word command named
"exec php -q myfile"
with no arguments.
Adding an 'eval' splits this up, but adds a second round of
interpretation. This makes a difference if any of your variables have
special characters in them.
Eg:
set myfile {c:\windows\system32}
catch {exec ls $myfile} res
=> returns 0, directory listing is in $res
catch {"exec ls $myfile"} res
=> returns 1, invalid command name "exec ls c:\windows\system32"
catch {eval "exec ls $myfile"} result
=> returns 1, /usr/bin/ls: c:windowssystem32: No such file or directory
The 'eval' has interpreted the contents of $myfile a second time and
stripped off the backslashes, thus you end up with a wrong file name
when calling the 'ls' command.
Rule of thumb: if you want to use catch around some command
some_cmd arg1 arg2 arg3
just add 'catch {' before the command and '}' after it.
catch { some_cmd arg1 arg2 arg3 }
Do _not_ add additional quoting. From there on, build up further
set err [catch { some_cmd arg1 arg2 arg3 }]
if {$err} { ... }
Or directly
if {[catch { some_cmd arg1 arg2 arg3 }]} { ... }
| The PHP script will prompt you to enter something:
|
| Enter your username: [here is where you enter something in the
| command line] Etc.
Hmm, most probably this does not work because TCL captures the output
of the process and returns it as result of the exec call. So you
don't see the prompt etc.
Try to redirect stdout and stderr when calling the php script, like
this:
catch { exec php -q myfile >@stdout 2>@stderr }
This will redirect stdout of the PHP script to TCLs stdout, and stderr
of the PHP script to TCLs stderr. stdin should already have been
handled by TCL. Again, the manpage for exec describes the details.
| Maybe if you clarified it a bit more I would know how to implement,
| as it is, I'm just as confused as before, I'm afraid and I'm sorry.
I hope this has not added to the confusion :-/
R'
[Back to original message]
|