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

Problem writing/reading to text file 1

Status
Not open for further replies.

JASONE25

Technical User
Jun 23, 2005
54
NL
He experts. I wrote this script but unfortunely when i run it i get the following erro. I am passing this script the number of songs as linke below:


the script supposed to write it to text file and play it but unfortunely it does. could any expert help me fix this error.i put permition for it as read and write but still does not work!Thanks
Code:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


Can't open songlist.txt at c:\inetpub\[URL unfurl="true"]wwwroot\cgi-bin2\textchat\multsong.pl[/URL] line 145.




Code:
#!/usr/bin/perl

 
SWITCH:
{

@pairs = split(/&/, $ENV{"QUERY_STRING"});

foreach $pair (@pairs) {
 ($name, $value) = split (/=/, $pair);
 $formData{"$name"} = $value;
}

$fname = $formData{name};

if( $fname eq "ID1" )
{
$fname="[URL unfurl="true"]http://localhost/songs/g1.rm";[/URL]
   last SWITCH;
}
if($fname eq "ID2")
{
$fname="[URL unfurl="true"]http://localhost/songs/g2.rm";[/URL]
last SWITCH;
      
}

if($fname eq "ID3")
{
$fname="[URL unfurl="true"]http://localhost/songs/g3.rm";[/URL]
last SWITCH;
      
}
if($fname eq "ID4")
{
$fname="[URL unfurl="true"]http://localhost/songs/g4.rm";[/URL]
last SWITCH;
      
}
DEFAULT:
{
$fname="[URL unfurl="true"]http://localhost/salma/m7.rm";[/URL]
last SWITCH;
}
}#END OF SWITCH BLOCK




$outfile= 'songlist.txt';
open(OUTPUT, ">$outfile")or die "Can't open $outfile";

close(OUTPUT);


#################################################################################
#Defult Subroutines
 


print <<method;

<html>
<head>
        <title>Voice Music</title>
</head>

<script language=JavaScript src="[URL unfurl="true"]http://localhost/dll.js">[/URL]
</script>


<body bgColor=#336699 leftmargin="0" topmargin="0">

#Real Audio Applet
<OBJECT ID=video1 CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" HEIGHT=60 WIDTH=285>
<PARAM NAME="controls" VALUE="ControlPanel,StatusBar">
<PARAM NAME="console" VALUE="Clip1">
<PARAM NAME="autostart" VALUE="true">
<PARAM NAME="src" VALUE="[URL unfurl="true"]http://localhost/cgi-bin2/songlist.txt">[/URL]
<EMBED SRC="$fname" type="audio/x-pn-realaudio-plugin" CONSOLE="Clip1" CONTROLS="ControlPanel,StatusBar" HEIGHT=60 WIDTH=285 AUTOSTART=true>
</OBJECT>

</body>

</html>

method
 
Is the file songlist.txt located in your CGI-BIN folder? You can get more information on why the file didn't open by adding a $! to your die command.

- Rieekan
 
Thank u for u reply. i placed the songlist.txt inside cgi-bin2 folder and its permetions are to read and wriet. I placed the $! infront of dia command and it gives me the following error :

Code:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


Permission deniedCan't open songlist.txt at c:\inetpub\[URL unfurl="true"]wwwroot\cgi-bin2\textchat\multsong.pl[/URL] line 145.


Code:
$outfile= 'songlist.txt';
open(OUTPUT, ">$outfile")or die$!, "Can't open $outfile";
 
Per the error, your web user account doesn't have access to read/write to that file. Change the file permissions to ensure the world can read and write that file and you should be good.

Also, change the die code to this. It's a little cleaner looking.
Code:
$outfile= 'songlist.txt';
open(OUTPUT, ">$outfile")or die, "Can't open $outfile: $!";

- Rieekan
 
Thanks Rieekean for your nice reply. Here is the permissions that i put :

script sources access => checked
Read=> checked
Write=> checked
log visit=> checked
index this resource=> checked

execute permissions: scripts and eecutables( from drop down box)

I went to IIS and went the the default server and then right clicked the cgi-bin2 which hold the script and selected the properties and a windows came and i set the permessions as above. I be happy if u tell me what is wrongs since still it does not work.Thanks
 
Ah, missed that it was an Windows/IIS issue. Check the properties of the file as well to make sure it's not set to a ReadOnly status (as has commonly occurred for me with things copied to Windows machines). It is definitely a permission problem with the file itself.

- Rieekan
 
Do your IUSR accounts have access to the CGI-BIN2 directory?
 
Rieekan thank u for u reply. could u tell me how i can check IUSR account.? I right clicked on the cgi-bin2 folder and clicked on property and securty i could not find any account as iusr! I am logged in my computer as an administrator and i checking it from same mechine and it does not work. Furthermore, do u think this script code is written corretly for collecing songs url and writing it to text file and load ing it ?Thanks
 
If you go into the properties of the folder, then choose the Security tab you should see the list of authorized users to the folder. With IIS, there are two accounts set up for the web server. The first being a User account (think of it similar to the NOBODY ID used by Apache) and a second account used for CGI applications running on the server. You need to make sure these accounts have access to the folder.

I don't work in Windows often for CGI things, so please feel free to visit the IIS group for help in ensuring this is set up correctly. This is forum41

- Rieekan
 
Rieekan many thanks to u i fixed the reading and writing problem. But now it only writes one song on the text file. If i select 2 and 3 it only writes the latest one which is 3. Is there a way to write multiple songs to text file since i am using check boxes . Like example below


Thanks
 
Great. OK, now lets work on the script. The problem I see with the script is that since you're using check boxes named the same, your only getting one hash key/value pair by the time you get to writing the information to the file. Try the following instead:

Code:
#!/usr/bin/perl

use strict;
use CGI;
use CGI:Carp qw/fatalsToBrowser/;
 
my @fname = param('name');
my $outfile= 'songlist.txt';
my %songs = (		"ID1" => "[URL unfurl="true"]http://localhost/songs/g1.rm",[/URL]
				"ID2" => "[URL unfurl="true"]http://localhost/songs/g2.rm",[/URL]
				"ID3" => "[URL unfurl="true"]http://localhost/songs/g3.rm",[/URL]
				"ID4" => "[URL unfurl="true"]http://localhost/songs/g4.rm",[/URL]
				"DEFAULT" => "[URL unfurl="true"]http://localhost/songs/m7.rm"[/URL] );

open(OUTPUT, ">$outfile")or die "Can't open $outfile: $!";

foreach $name (@fname);
{
	print OUTPUT $songs{$name} .'\n';
}

close(OUTPUT);

print <<METHOD;

<html>
<head>
        <title>Voice Music</title>
</head>

<script language=JavaScript src="[URL unfurl="true"]http://localhost/dll.js">[/URL]
</script>


<body bgColor=#336699 leftmargin="0" topmargin="0">

#Real Audio Applet
<OBJECT ID=video1 CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" HEIGHT=60 WIDTH=285>
<PARAM NAME="controls" VALUE="ControlPanel,StatusBar">
<PARAM NAME="console" VALUE="Clip1">
<PARAM NAME="autostart" VALUE="true">
<PARAM NAME="src" VALUE="[URL unfurl="true"]http://localhost/cgi-bin2/songlist.txt">[/URL]
<EMBED SRC="$fname" type="audio/x-pn-realaudio-plugin" CONSOLE="Clip1" CONTROLS="ControlPanel,StatusBar" HEIGHT=60 WIDTH=285 AUTOSTART=true>
</OBJECT>

</body>

</html>

METHOD

I will say that this is just something thrown together, but it will handle easily any additions you want to make to your song list without adding a ton of code. All you need to do is add the information to the song hash and you're off and running.

Hope this helps,
- Rieekan
 
Many thanks Rieekan for helping me. I tried to run the above script by type the following url:


An i got this error:


Code:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


syntax error at c:\inetpub\[URL unfurl="true"]wwwroot\cgi-bin2\textchat\mult.pl[/URL] line 5, near "use CGI:"
Execution of c:\inetpub\[URL unfurl="true"]wwwroot\cgi-bin2\textchat\mult.pl[/URL] aborted due to compilation errors.

I installed perl on my my local mechine . Do u think there is some thing wrong with installation that i get this syntax error?Thanks
 
The issue appears to be that you put a colon:)) where a semi-colon is needed (;).

- Rieekan
 
Thanks u for reply . I changeed this line
Code:
use CGI:Carp qw/fatalsToBrowser/;
to
Code:
use CGI::Carp qw/fatalsToBrowser/;

But unfortuently i get the following error:


Code:
Software error:
Global symbol "$name" requires explicit package name at c:\inetpub\[URL unfurl="true"]wwwroot\cgi-bin2\textchat\mult.pl[/URL] line 17.
syntax error at c:\inetpub\[URL unfurl="true"]wwwroot\cgi-bin2\textchat\mult.pl[/URL] line 17, near ");"
Global symbol "$name" requires explicit package name at c:\inetpub\[URL unfurl="true"]wwwroot\cgi-bin2\textchat\mult.pl[/URL] line 19.
Global symbol "$fname" requires explicit package name at c:\inetpub\[URL unfurl="true"]wwwroot\cgi-bin2\textchat\mult.pl[/URL] line 24.
Execution of c:\inetpub\[URL unfurl="true"]wwwroot\cgi-bin2\textchat\mult.pl[/URL] aborted due to compilation errors.

For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.

I be happy if u help me fix these errors.Thanks
 
Ah, for that part of the script I had just copied/pasted your code. My mistake. Use this instead:

Code:
#!/usr/bin/perl

use strict;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;

my $startName;
my @fname = param('name');
my $outfile= 'songlist.txt';
my %songs = (        "ID1" => "[URL unfurl="true"]http://localhost/songs/g1.rm",[/URL]
                "ID2" => "[URL unfurl="true"]http://localhost/songs/g2.rm",[/URL]
                "ID3" => "[URL unfurl="true"]http://localhost/songs/g3.rm",[/URL]
                "ID4" => "[URL unfurl="true"]http://localhost/songs/g4.rm",[/URL]
                "DEFAULT" => "[URL unfurl="true"]http://localhost/songs/m7.rm"[/URL] );

open(OUTPUT, ">$outfile")or die "Can't open $outfile: $!";

foreach my $name (@fname);
{
    print OUTPUT $songs{$name} .'\n';
    $startName = $name;
}

close(OUTPUT);

print <<METHOD;

<html>
<head>
        <title>Voice Music</title>
</head>

<script language=JavaScript src="[URL unfurl="true"]http://localhost/dll.js">[/URL]
</script>


<body bgColor=#336699 leftmargin="0" topmargin="0">

#Real Audio Applet
<OBJECT ID=video1 CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" HEIGHT=60 WIDTH=285>
<PARAM NAME="controls" VALUE="ControlPanel,StatusBar">
<PARAM NAME="console" VALUE="Clip1">
<PARAM NAME="autostart" VALUE="true">
<PARAM NAME="src" VALUE="[URL unfurl="true"]http://localhost/cgi-bin2/songlist.txt">[/URL]
<EMBED SRC="$startName" type="audio/x-pn-realaudio-plugin" CONSOLE="Clip1" CONTROLS="ControlPanel,StatusBar" HEIGHT=60 WIDTH=285 AUTOSTART=true>
</OBJECT>

</body>

</html>

METHOD
 
Thanks Rieekan . I tried to run the above code but it complains about :
print <<METHOD;


Code:
Software error:
Can't find string terminator "METHOD" anywhere before EOF at c:\inetpub\[URL unfurl="true"]wwwroot\cgi-bin2\textchat\mult2.pl[/URL] line 26.

For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.
 
Ah, yes. There needs to be a blank line after the word METHOD.

- Rieekan
 
:-(( now this one :


Code:
Software error:
Undefined subroutine &main::param called at c:\inetpub\[URL unfurl="true"]wwwroot\cgi-bin2\textchat\mult2.pl[/URL] line 8.

For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top