P
Patrick
#! /usr/bin/perl
#
# Minimal Launcher by Patrick Staight
#
# This script is a minimal illustration of a problem I'm having:
# It works fine from the command prompt, but just leaves an empty
# file when called from a web page. All permissions are set correctly.
# IE:
# -rwxr--r-- 1 staightp csmajs 228 May 12 11:46 index.html*
# -rwx--x--x 1 staightp csmajs 1198 May 12 12:44 get_launch.pl*
# -rwx--x--x 2 staightp csmajs 13908 May 5 23:52 token*
#
#
# It is supposed to:
# - Immediately return the status page "Launcher".
# - Hand off its stdin to a program called token.
# (Token can handle any input and only outputs word characters and \n.)
# - Grab the output of token, do some work and put it in a temp file.
#
# Note: Token's output has a guaranteed size, nothing else may be
# written to disk.
use File::Temp qw( tempfile );
($tmp,$name)= tempfile("Lanch_XXXX" , SUFFIX =>'.tmp');
if(fork)
{
print(
'Content-type: text/html
<HTML>
<HEAD><TITLE>Launcher</TITLE><HEAD>
<BODY>
The name of the file is:'.$name.'<br>
It will be available soon<br>
</BODY>
</HTML>
');
exit;
}
else
{
if(open(TOKEN_PIPE, "-|"))
{
while(<TOKEN_PIPE>)
{
chomp;
#will do stuff here
print $tmp "$_\n"
}
close TOKEN_PIPE or die("token failed: $!");
close $tmp or die("couldn't close tmp file: $!");
exit;
}
else{exec token;}
}
#
# Minimal Launcher by Patrick Staight
#
# This script is a minimal illustration of a problem I'm having:
# It works fine from the command prompt, but just leaves an empty
# file when called from a web page. All permissions are set correctly.
# IE:
# -rwxr--r-- 1 staightp csmajs 228 May 12 11:46 index.html*
# -rwx--x--x 1 staightp csmajs 1198 May 12 12:44 get_launch.pl*
# -rwx--x--x 2 staightp csmajs 13908 May 5 23:52 token*
#
#
# It is supposed to:
# - Immediately return the status page "Launcher".
# - Hand off its stdin to a program called token.
# (Token can handle any input and only outputs word characters and \n.)
# - Grab the output of token, do some work and put it in a temp file.
#
# Note: Token's output has a guaranteed size, nothing else may be
# written to disk.
use File::Temp qw( tempfile );
($tmp,$name)= tempfile("Lanch_XXXX" , SUFFIX =>'.tmp');
if(fork)
{
print(
'Content-type: text/html
<HTML>
<HEAD><TITLE>Launcher</TITLE><HEAD>
<BODY>
The name of the file is:'.$name.'<br>
It will be available soon<br>
</BODY>
</HTML>
');
exit;
}
else
{
if(open(TOKEN_PIPE, "-|"))
{
while(<TOKEN_PIPE>)
{
chomp;
#will do stuff here
print $tmp "$_\n"
}
close TOKEN_PIPE or die("token failed: $!");
close $tmp or die("couldn't close tmp file: $!");
exit;
}
else{exec token;}
}