blowupp has asked for the wisdom of the Perl Monks concerning the following question:

Not sure if I should update like this so apologies if its duff form:
Proper ticks, header line with \n\n - and a sensible path. It worked. Thanks very much for all the info folks. I have extra question:

My aim is to run a script from a link (turning the radio back to my favourite channel after colleagues put on handbag house channels and go home) These are the commands I thought would work - but they dont.
system('bash /Library/WebServer/CGI-Executables/radio.sh '); #system('osascript /Applications/radioscripts/Switch_iTunes_Subflow.ap +p'); #system('osascript /Library/WebServer/CGI-Executables/Switch_iTunes_Su +bflow.app');

The bash.sh works from a shell & I have given ownership to "www"
original Post::: Hello Monks - may I request some "local knowledge": This works on my ISP managed online server but how do I make it work on my local mac box (trying to setup some housekeeping scripts initiated by local browser link ) ?
Apache error log says : Premature end of script headers: /Library/WebServer/CGI-Executables/radio.pl
#! /usr/bin/perl use strict; use CGI qw(:standard); use Fcntl qw(:DEFAULT :flock); system(`mkdir /cgi-bin/NEW`);

Replies are listed 'Best First'.
Re: system commands in os x apache
by ikegami (Patriarch) on Mar 11, 2010 at 17:13 UTC

    You're executing your script as a CGI script, but you don't follow the CGI protocol. You need to print out a CGI header. Look at CGI's docs for "header".

    Also,
    system(`mkdir /cgi-bin/NEW`);
    should be
    system('mkdir /cgi-bin/NEW');
    or just
    mkdir('/cgi-bin/NEW');

    Your version executes mkdir, captures its output, then executes the output.

      mkdir('/cgi-bin/NEW');

      Also, the path /cgi-bin/NEW looks suspicious, as it would either try to create a directory in the filesystem's root directory / (where the webserver user typically has no permission to write), or in /cgi-bin, which probably doesn't exist. And in case there is no /cgi-bin, Perl's mkdir would also need to create two nested directories in one go, which it generally doesn't.

      Maybe the OP rather simply wants something like 'NEW' (assuming the current directory of the CGI script is the cgi-bin directory (not unlikely)).  Otherwise, the absolute physical path to the web-account's cgi-bin in the filesystem would likely be more appropriate.

Re: system commands in os x apache
by sierpinski (Chaplain) on Mar 11, 2010 at 17:11 UTC
    You need to tell the browser what type of content to expect, and this is done with the following:
    print "Content-type: text/html\n\n";
    Note that you have to have two \n's at the end, or else it won't work.

    There can be other causes for that error, but most of the time that's the reason. Put it towards the top before you try to execute any other commands and see if that helps.

    Update: Take a look here, that will show you more about using HTML headers and footers. There are built-in function for headers and footers for html, so you don't have to print the HTML/BODY/etc tags.

    /\ Sierpinski