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

CGI opening files on NT4

Status
Not open for further replies.

Loon

Programmer
May 24, 2000
100
GB
Folks,
long time no speak.. hurray for project work slowing down for a bit...

My problem is that I am 'porting' a perl script from a Unix box to an NT box. My problems are that when I try and open a file (for reading) with:

Code:
open (INF, "example.txt") or print "Couldn't open example.txt ($!)"

This works on the Unix box (looking in the local directory for the file) but not on the NT 4 box where it comes back with "File not Found".

Other than file permissions (which are read-global) has anyone had problems on NT4 before? The rest of my script is working just not the opens.

Cheers
Loon [sig][/sig]
 
Loon:

Hmm. I have never experienced a problem like that.

Perhaps it is in the die part of the open function.

The way that I have seen most file openings is like this:

[tt]
open(FILE, "file.txt") || die ("Can't open file: $!");
# do stuff with the file
close(FILE);
[/tt]

I have never seen it like you have done it up there. I could be wrong, but that is just what I have seen for the way files are opened in Perl.

Hope this helps.

-Vic [sig]<p>vic cherubini<br><a href=mailto:malice365@hotmail.com>malice365@hotmail.com</a><br><a href= software</a><br>====<br>
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director<br>
Wants to Know: Java, Cold Fusion, Tcl/TK<br>
====[/sig]
 
Vic,
don't think it's the opens themselves, it's actually turned out to be a directory problem. The script is residing on an ISP.

The file not found error was just too obvious to be anything other than Perl not finding the file. So I decided to check out where Perl would create a file. I added a file creation to my script:
Code:
open (OUTF, &quot;>test.tst&quot;);
print OUTF &quot;TESTING TESTING 1 2 3&quot;;
close(OUTF);

Low and behold it created the file in the top level directory of my ISP account, even though the page calling the script was in a sub-directory and the Perl script in a cgi-bin directory.

Is there anyway of setting which directory my scripts will write files to? Or is it just a case of setting a local path in the commands themselves, e.g.:
Code:
open (INF, &quot;./sub-dir/filetoopen.htm&quot;);
etc...

Any thoughts appreciated.
Cheers
Loon

[sig][/sig]
 
Well, I guess that you could define a variable such as:

[tt]
$dataLocation = &quot;location/of/the/file&quot;;
$fileName = &quot;file.txt&quot;;

open (FILE, &quot;$dataLocation/$fileName&quot;) || die(&quot;Can't open file: $!&quot;);
# do stuff with file
close(FILE);

[/tt]

That is the only way that I know to change the directory in which a file is located it.

If you want to move files around, you could use the chdir command to change the directory and then move the file to that directory.

Hope this helps.

-Vic [sig]<p>vic cherubini<br><a href=mailto:malice365@hotmail.com>malice365@hotmail.com</a><br><a href= software</a><br>====<br>
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director<br>
Wants to Know: Java, Cold Fusion, Tcl/TK<br>
====[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top