Link to home
Start Free TrialLog in
Avatar of imidms
imidms

asked on

Path Setting problem

Hi to all,

I am running a perl script under Windows 2003 IIS 6.0 server.In my script i try to read a html file.For that i have use the relative path

my $file="../templates/myfile.html";

But it says the file is not exist,which is existing.But when i use absolute path
(my $file="C:/Inetpub//cgi-bin/elearning/templates/myfile.html";) its working fine.

my wondering is that how do i do that path setting.

Thanks
Rajiv
Avatar of ozo
ozo
Flag of United States of America image

what command are you executing when it says "the file is not exist"?
you can
chdir "C:/Inetpub//cgi-bin/elearning/templates" or warn "chdir $!";
then ../templates/myfile.html and C:/Inetpub//cgi-bin/elearning/templates/myfile.html should be the same file
Avatar of Tintin
Tintin

Assuming your script is a CGI script, then you can not assume that the current working directory of the script is the same location as the script itself.  

With a lot of IIS setups, the current working directory will actually be the document root, rather than the cgi-bin directory.

Try using

my $file="cgi-bin/templates/myfile.html";
Avatar of imidms

ASKER

I have a perl script in C:/Inetpub/cgi-bin/elearning/query/ directory.My html file which i have to read is placed in C:/Inetpub/cgi-bin/elearning/templates/ directory so if i read the html file i can do

my $file="../templates/myfile.html";
open(FH,$file) or die $!;
my @array=<FH>;
close(FH);
Here it says no file or directory.
But if i change '../templates/myfile.html' to 'C:/Inetpub//cgi-bin/elearning/templates/myfile/html' it is working fine.

Regards
Rajiv

What happened when you tried my suggestion.
then I suggest you change '../templates/myfile.html' to 'C:/Inetpub//cgi-bin/elearning/templates/myfile/html'


If you want to see where the .. would be starting from
use Cwd;
print getcwd;
Avatar of imidms

ASKER

Sorry for the late reply,
I have tried your suggestion but it gives the same error

cgi-bin/elearning/adm-temp/elearning_string_temp.html No such file or directory
Did you try the suggestion from ozo.  The problem is likely that the working directory is not the same directory the script is in.  The code ozo provided will tell you your working directory.
I took a guess at what the current working directory is.  Remember the CGI spec does not guarantee your working directory is where the script is located.
I'm not sure what the problem is
you have something that works
(my $file="C:/Inetpub//cgi-bin/elearning/templates/myfile.html";) its working fine.
you can set the current working directory to be what you want
chdir "C:/Inetpub//cgi-bin/elearning/templates"
you can find out what the current working directory is
use Cwd;
print getcwd;
what else do you need?
Avatar of imidms

ASKER

Thank its working
What did you do to fix it?
Avatar of imidms

ASKER

I have found the working directory is /cgi-bin but i did assume that the script directory is a working directory.


So i have changed the directory '../adm-temp/myfile.html'  to 'elearning/adm-temp/myfile.html.

Regards
Rajiv
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial