Tags:
create new tag
, view all tags

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

TWiki version: TWikiRelease01Feb2003
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS:  
Web server:  
Perl version:  
Client OS:  
Web Browser:  

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

Topic revision: r3 - 2003-12-02 - PeterThoeny
 
Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Download TWiki
TWiki logo Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.