简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM