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!

reading and writing files through a browser

Status
Not open for further replies.

rshandy

Technical User
Dec 26, 2003
91
US
I have a script that executes from an html form submission. Its all run on an internal iis server. The script resides in the cgi-bin on the iis server that reads/and writes to an external js file. It works fine and then all of the sudden I get a software error:

Error opening file during getSubCat \\servername\inetpub\Invalid argument.

I've been banging my head into the wall for a few days now and can't seem to figure out why it produces the error and stops working.


Here's a snippet of the code:

#!/usr/local/bin/perl5
use strict;
use CGI qw:)standard);
use CGI::Carp qw /fatalsToBrowser/;
my $CatPage=param('Category');
print header;
print start_html('testpage');
print<<DDP;
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body bgcolor="#FFFFFF" text="#000000">
<script language="JavaScript" type="text/javascript" src=" <table cellspacing="0" cellpadding="0" border="0" valign="top" bgcolor="#ffffff" width="10">
<tr>
<td valign="top" width="1"><img src="/images/transparent.gif" border="0" width="1" height="1"><br></td>
<td valign="top" width="10">&nbsp; </td>
<td width="1"><img src="/images/transparent.gif" border="0" width="1" height="1"><br></td>
</tr>
</table>

<table cellpadding="0" cellspacing="0" border="0" width="750">
<tr valign="top">
<td>
<div align="left"><img src="/images/transparent.gif" width="100" height="2"></div>
</td>
<tr>
<td align="left"><h1><font face="Arial, Helvetica, sans-serif"><b><font size="4"> Category Page Editor</font></b></font></h1>
</td>
</tr>
<tr>
<td align="left"><img src="/images/transparent.gif" width="100" height="18"></td>
</tr>
<tr>
<td align="left" >
<table cellspacing="0" cellpadding="1" border="0" width="100%" >
<tr>
<td align="center" colspan="4" rowspan="2" bgcolor="#CCCCFF" >
<table cellspacing="0" cellpadding="0" border="0" width="100%" >
<tr>
<td align="center"><img src="/images/transparent.gif" width="10" height="18"><br><img src="/images/transparent.gif" width="10" height="8"><font size="3" face="Arial, Helvetica, sans-serif">Step
1: You're editing Category page <b>$CatPage</b>:</font><input type="hidden" name="SubCategory" value="$CatPage"></td>
</tr>
<tr>
<td align="left"><img src="/images/transparent.gif" width="100" height="18"></td>
</tr>
DDP
&getSubCat();
print<<DDP2;
<tr>
<td><img src="/images/transparent.gif" width="10" height="15">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</table>
</body>

DDP2
print end_html;

sub getSubCat {
my %productData;
my @scCategory;
my $xx;
my $count=0;
my $DCcatDB="//pathtodb/product4sub.sdb";
my ($category,$blank);
my $JSexternal = "\\\\servername\\inetpub\\ open (SubCat, ">$JSexternal") || die "Error opening file during getSubCat $JSexternal\n$!\n";
open (FILE, "$DCcatDB") or die "Cannot open database ($DCcatDB):$!\n";
while (<FILE>) {
chomp;
($category,$blank)=split(/,/);
if ($category ne "SubCategory") {
$scCategory[$count]=$category;
$count++;
}
}
close FILE;
@sortSubCat = sort @scCategory;
$subCatCount = $count;
print SubCat "function GetSubCat(subcatnumber) {\n";
print SubCat "var SubCatCount=$count;\n";
print SubCat <<SubCatDiv;
var divwriteInit="<select name=\\"CrateSubCategory"+subcatnumber+"\\" style=\\"font-size: 9.5\\" onChange=\\"ShowHide('catsubdrop"+subcatnumber+"','1','createPage"+subcatnumber+"');showsubCat('catYn"+subcatnumber+"');GetProdGroup('"+subcatnumber+"')\\">"+
"<option value=\\" \\" selected> - - - - - - - - - - - - -"+
"Choose Crate Subcategory - - - - - - - - - - - - - </option>";
var DCSubCat=new Array('300');
SubCatDiv
my $arrayValue=0;
foreach $xx (@sortSubCat) {
print SubCat "DCSubCat[$arrayValue]=\"$xx\";\n";
$arrayValue++;
}
print SubCat <<SubCatDiv2;
var subcatdropdwn;
var subcatdroptotal;
i=0;
var DCsCat;
for (i=0; i < SubCatCount; i++) {
DCsCat=DCSubCat;
subcatdropdwn="<option value=\\""+DCsCat+"\\">"+DCsCat+"</option>";
subcatdroptotal=subcatdroptotal+subcatdropdwn;
}
if (document.getElementById) {
document.getElementById("CrateSubCatDrop"+subcatnumber).innerHTML = divwriteInit+subcatdroptotal+"</select>";
}
SubCatDiv2
print SubCat "}\n";
close SubCat;
}


If I log out off of the server and log back in, the script functions fine - permissions or authentication issue?
Thanks,
Rich
 
There are all kinds of things that could be going wrong here
Code:
  my $JSexternal = "\\\\servername\\inetpub\\[URL unfurl="true"]wwwroot\\cgi-bin\\js\\subCat.js";[/URL]
   open (SubCat, ">$JSexternal") || die "Error opening file during getSubCat $JSexternal\n$!\n";

Is this file located on a different machine or is it a local file? If it is local I would change the path to be the local path and not the UNC (I think that's what it's called) path.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Your script is actually printing an external javascript file? That sounds rather unusual. What happens if the javascript file is written to by multiple users at the same time?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks for the response guys

Travis:The file is located on a separate machine a windows2000 server running IIS 5.0. The network is a win2000 server with approximately 10 XP members of the domain. I did originally have the scripts running from the "scripts" directory, but found I could better handle the permissions in the cgi-bin.

Kevin:The server is not accessible beyond the LAN. The script is only used by a handful of people, so I'm not too worried (for now) about someone overwriting the script; plus the js array doesn't change unless the database that it extracts the info from changes, and I intentionally rewrite the script to accommodate for any changes to the db.

The external js is written to populate an array to allow the user to select products to be written to html file that will then be ftp'd to a remote server.

I know the process seems a bit archaic but unfortunately,I'm building additional functionality for our websites that uses an old ecommerce technology that reads a flat file database to generate html product pages. It doesn't create a multilevel structure (category, subcategory pages, etc) and I have been hardcoding these pages up until now. To make matters worse, the flat file database is generated and modified by yet another program.

This new feature needs to read in the current flat file database, populate a js array to which will allow the user to select a page they want to generate and populate with any product within unlimited sub categories. The only way I could see doing this with my level of expertise was to create an external js array and a static html page that reads in the array so the user can select the products they want to include on that page and then submit to another perl script that creates a configuration file for the page thats being created (for editing rather than creating anew) and then write the static html page. The file then gets ftp'd to a remote hosted server. The next step will be an automated ftp process.

With that said, why would the process all of the sudden spew out an error describing an invalid argument. Is it an active Perl issue, iis server issue? Am I not properly opening the file from a authentication standpoint? Any suggestions to buzz it out?

Thanks again.


 
It does sound like a race condition error - trying to open a file that's already open.

I've seen this before from time to time, I would be that it's to do with closing the file subCat.js in that subroutine.

Is the final } getting written to the file? I'm wondering if the code following there heredocument is being executed.

Mike

When working on any project the value of other people is exactly that - they are other people, with views that don't necessarily match yours. This mismatch, between their views and the view you've been contentedly assuming is right, is where that value lies.
 
I checked the file. The final } is being written to the file.
Also, during the next part of the process, I submit that page to another script which writes to a txt cfg file - it sometime produces the same type of error.

cannot open database (\\servername\inetpub\ argument

Then, sometimes, I'll click the back button on the browser, resubmit, and viola, it works fine!?
 
Sounds like a problem with using the network share or with multiple people trying ot do it at once. Possibly you could queue this up on the local machine and try and copy it over in a different script. Have you looked at the logs of the remote server to see if anything is going on with that box? Maybe you can change your original script to try and open and if it fails to wait x seconds and try again?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Maybe you can change your original script to try and open and if it fails to wait x seconds and try again?"

Yup - That was going to be my next suggestion.

Mike

When working on any project the value of other people is exactly that - they are other people, with views that don't necessarily match yours. This mismatch, between their views and the view you've been contentedly assuming is right, is where that value lies.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top