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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why is this script hanging the webpage? it's short ;)

Status
Not open for further replies.

Nutthick

MIS
Jan 14, 2004
126
GB
I've survived with Perl so far, but I'm starting to stretch myself now, and my lack of knowledge is starting to let me down. I'm trying to produce a page that when the user clicks on a button, the script gets called, but the page doesn't change. Basically the script triggers an MP3 to play on the server, but I want to keep the screen the same so the user can click around the different sounds.

At the moment the sound starts, but the page then tries to load something and then sits there till the track finishes, when I get an error 500. I'm guessing this is something to do with qx, but I'm not sure. Can anyone help.

Thanks

Code:
#!/usr/bin/perl

# Parse the passed data
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
	($name, $value) = split(/=/, $pair);
	$value =~ tr/+/ /;
	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	$FORM{$name} = $value;
}

$temp = trim($FORM{'Track'});
$Track = "/home/jellyd/play.sh -f $temp"; # Command construction

qx[$Track];  # Call the mp3 script

exit 0;

# Removes leading and trailing spaces
sub trim {
	my @out = @_;
	for (@out)
		{
			s/^\s+//;
			s/\s+$//;
		}
	return wantarray ? @out : $out[0];
}
 
The qx is a synchronous call i.e. it blocks. From what I can see from the doc, fork() might do it, but there are some issues.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top