Summary: Run a CGI script from a recipe illustration
Version: 2012-09-08
Status: As is
Maintainer: PmWiki community
Categories: PmWiki developer
Users: (view? / edit)
Discussion: RunCGI-Talk

How do I invoke a CGI script from a PmWiki recipe?

Try this, in the example the script being executed is

<?php if (!defined('PmWiki')) exit();
# This recipe illustrates calling a CGI program from a PmWiki recipe.
# Version date
$RecipeInfo['RunCGI']['Version'] = '2012-09-08';
$FmtPV['$RunCGI'] = $RecipeInfo['RunCGI']['Version']; // return version as a custom page variable
# 2012-09-05 Initial version

# declare $RunCGI for (:if enabled RunCGI:) recipe installation check
global $RunCGI; $RunCGI = 1;
  Copyright 2012
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.  
Markup('RunCGI', 'fulltext', '/\\(:runcgi:\\)/ei',
function RunCGI() {
  $retval = 'retval is ';  
  $lastline = '';
  $output = '';
  $lastline = exec("../cgi-bin/", $output); // return result of executing file
  $retval .= ' exec:' . pre_r($output);
  $retval .= ' fgc:' . pre_r(file_get_contents('../cgi-bin/')); // return contents of file

  return $retval;


Enter your recipe's description here.


  • save the above example as MyRecipe.php in the /pmwiki/cookbook/ directory
  • add include_once("$FarmD/cookbook/MyRecipe.php"); to config.php
  • add (:runcgi:) to a wiki page




See PHP's

See from PmWiki

  • pre_r is defined in pmwiki.php as
    function pre_r(&$x)
      { return '<pre>'.PHSC(print_r($x, true)).'</pre>'; }
  • Markup
  • Keep

See also

  • PmWikiDeveloper   Information for PmWiki and recipe developers
  • PmWikiInternals   Documentation of PmWiki Internal functions and operation
  • Functions   Brief description of some of PmWiki's internal functions available to cookbook recipe authors and custom markup developers
  • FunctionList   A simple list of the functions provided by PmWiki
  • Functions   How some of the functions in pmwiki.php work

Change log / Release notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See also


  • simon September 07, 2012, at 11:50 PM


See discussion at RunCGI-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.