Question
Hello
How to execute a script in a page. To elaborate;
Since the TWiki txt pages also supports html tags, I wanted to know if I can write a script ... /script
and execute it.
My requirement is; I want to execute a small script and store the output of the script in a variable (Twiki variable)
which I want to use in further processing.
The script which I have writen is to check for the OS if it is window it returns a path C:\foo\foo1 else if UNIX
it returns /mnt1/foo/foo1 and Then I want to use this path to find some files.
Hope my question is clear.
=thanks
Madan
Environment
--
MadanKumarThangavel - 27 Nov 2003
Answer
In Perl you can execute any script simply with backticks. Untested example, add to your DefaultPlugin.pm:
# =========================
sub commonTagsHandler
{
### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead
$_[0] =~ s/%MYSCRIPT%/&_handleMyScript()/ge;
}
# =========================
sub _handleMyScript
{
my $date = `/bin/date`; # assuming Unix environment
return $date;
}
If you want to figure out the OS of the server where TWiki is running, see OS detection code in
twiki/lib/TWiki.cfg.
If you want to test the OS of the client browser check the
HTTP_USER_AGENT environment variable. This might not be set in all cases though.
--
PeterThoeny - 02 Dec 2003