Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using $SIG{__DIE__} and exec

Status
Not open for further replies.

Krel

Programmer
Feb 3, 2002
135
0
0
CA
My CGI script accesses a mysql database, and it won't work in mysqld.exe isn't running. Sometimes, that program gets is shut down for various reasons. In my script, I have it script die if it can't connect to the database, and then I set $SIG{__DIE__} to exec mysqld.exe as the last thing it does.

When the script dies because the database connection didn't work, mysqld.exe is started as I want. However, I also want it to display a message in the browser indicating that refreshing your screen will fix the problem (because this time mysqld.exe will be running). However, my script just keeps running and eventually times out without showing any output. As I said, though, the exec is done successfully.

Code:
$|  = 1;  
$SIG{__DIE__} = sub { 
  print "Content-type: text/html\n\n $_[0]"; 
  exec 'C:\apache\mysql\bin\mysqld.exe' if $_[0]=~ /MySQL/; 
};
my $DatabaseConnection  = DBI->connect('dbi:mysql:lotto649') or die "MySQL Connection Failed.  Please use your refresh button and everything should work normally. $!";
 
It does the exact same thing with system()... Could it be because mysqld.exe never really "quits" (it just stays there), so the perl program never gets a response and thus times out? If so, how could I get around this?
 
Oh yeah, and I tried using backticks in a void context and that timed out as well. The script does NOT time out if I don't use system, exec or backticks, so I'm certain those are the problem. All three methods do start the program correctly, though.
 
Just thinking out loud here.

Is there a way to check to see if mysqld.exe is running before you try to connect and then if it's not then start it?

tgus

____________________________________________________
A father's calling is eternal, and its importance transcends time.
 
I thought about that, but I would probably run into the same problems trying to start mysqld.exe and run the script as I'm having now.

Basically, is there any way that perl can execute a program without expecting a waiting for any kind of return value?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top