Can't fork exec from webpage, problem is not permissions

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;}
}
 
N

nobull

else{exec token;}

It is not good practice to use bareword strings.

You should print out the reason why exec fails if it fails. It is most
likely that it does fail from the symptoms you describe.

Random shot-in-the-dark does $ENV{PATH} contain the directory where
the executable is?

Note if you were relying on the fact that 'token' is in the current
working directory then two things to remember:

1) In Unix the CWD (i.e. '.') is only in the search path if it
actually is.
Unlike some OSs where is assumed to be always.

2) The current working directory may not be what you think it is.

This newsgroup does not exist (see FAQ). Please do not start threads
here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top