Pow programming languages
From PlainOldWebserver
This document describes how to run POW in programming languages other than Javascript.
Contents |
PHP
First, download and install PHP. In htdocs/system/startup.sjs
<?sjs
pow_server.APP_HANDLERS['php'] = '/usr/bin/php';
?>
In the menu, Tools->POW->Options...->Add mime type, add "php text/html Binary=unchecked" to the list if it is not there. Restart POW or close and reopen all browser windows. A script named test.php in the htdocs directory will work.
test.php
<?php
echo "Hello world"
?>
Python
First, download and install Python. In htdocs/system/startup.sjs
<?sjs
pow_server.APP_HANDLERS['py'] = '/usr/bin/python';
?>
In the menu, Tools->POW->Options...->Add mime type, add "py text/html Binary=unchecked" to the list if it is not there. Restart POW or close and reopen all browser windows. A script named test.py in the htdocs directory will work.
test.py
print "Hello world"
Perl
First, download and install Perl. In htdocs/system/startup.sjs
<?sjs
pow_server.APP_HANDLERS['pl'] = '/usr/bin/perl';
?>
In the menu, Tools->POW->Options...->Add mime type, add "pl text/html Binary=unchecked" to the list if it is not there. Restart POW or close and reopen all browser windows. A script named test.pl in the htdocs directory will work.
test.pl
print "Hello world!\n";
TCL
First, have TCL shell (tclsh) installed and working. In htdocs/system/startup.sjs
<?sjs
pow_server.APP_HANDLERS['tcl'] = '/usr/bin/tclsh';
?>
(put a correct path to your tcl here)
In the menu, Tools->POW->Options...->Add mime type, add "tcl text/html Binary=unchecked" to the list if it is not there. Restart POW or close and reopen all browser windows. A script named test.tcl in the htdocs directory will work. For example, have a script like this:
test.tcl
puts "Hello, world!"
You can also use this script to reveal all tcl variables set:
tclinfo.tcl
puts "Content-Type: text/plain; charset=utf-8\n"
foreach i [info vars] {
if [array exists $i] {
foreach {j k} [array get $i] { puts "[subst $i]($j) = $k" }
} else {
puts "$i = [subst $$i]"
}
}
Ruby
First, download and install Ruby. In htdocs/system/startup.sjs
<?sjs
pow_server.APP_HANDLERS['rb'] = '/usr/bin/ruby';
?>
In the menu, Tools->POW->Options...->Add mime type, add "rb text/html Binary=unchecked" to the list if it is not there. Restart POW or close and reopen all browser windows. A script named test.rb in the htdocs directory will work.
test.rb
3.times { |i| puts "Hello World from Ruby - #{i}" }
output from http://localhost:6670/test.rb
Hello World from Ruby - 0 Hello World from Ruby - 1 Hello World from Ruby - 2
This uses the CGI library.
require 'cgi'
cgi = CGI.new("html4")
name = cgi.params['name']
if (name.empty?)
name = '(no name)'
end
cgi.out {
cgi.html {
cgi.body {
cgi.h1 { "Welcome to POW" } +
cgi.p { "Hello, #{name}!" }
}
}
}
Result from http://localhost:6670/test.rb?name=Dave
Welcome to POW Hello, Dave!
