gettingthere
gettingthere

Reputation: 19

Restarting perl cgi script

After searching around I found this command exec($^X, $0, @ARGV); which restarts a perl script. However when I do this my script runs normally but has Content-Type: text/html infront of the expected output. I was wondering if this was the correct way to restart my perl cgi script.

EDIT:

elsif (defined param("again")){
    exec($^X, $0, @ARGV);
    exit;
}

When the script restarts it's supposed to print My guess is: 50 but it prints Content-Type: text/html My guess is: 50

Upvotes: 0

Views: 385

Answers (1)

syck
syck

Reputation: 3039

The first time you output it, it is used as a header (and not displayed), the second time as part of the content.

Add a parameter to @ARGV so that you can check whether the script was already restarted and therefore the header should not be sent anymore.

EDIT: I have just seen what is your intended use for this script. In an online game context, it would of course be preferable to refresh, redirect or simply provide a link or form submission to run the script again.

Solutions like this, where you restart a script (or run another) within the same http connection rather make sense for workhorse or surveillance scripts, for example to keep the memory footprint low. But it is a very rarely seen animal.

Upvotes: 2

Related Questions