Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Path Setting problem

Posted on 2008-06-23
13
Medium Priority
?
206 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:imidms
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 21844350
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
0
 
LVL 48

Expert Comment

by:Tintin
ID: 21844378
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";
0
 

Author Comment

by:imidms
ID: 21844458
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

0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 48

Expert Comment

by:Tintin
ID: 21844500
What happened when you tried my suggestion.
0
 
LVL 84

Expert Comment

by:ozo
ID: 21844519
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;
0
 

Author Comment

by:imidms
ID: 21845269
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
0
 
LVL 39

Expert Comment

by:Adam314
ID: 21846484
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.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 21849457
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.
0
 
LVL 84

Expert Comment

by:ozo
ID: 21850719
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?
0
 

Author Comment

by:imidms
ID: 21852814
Thank its working
0
 
LVL 48

Expert Comment

by:Tintin
ID: 21852903
What did you do to fix it?
0
 

Author Comment

by:imidms
ID: 21852954
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
0
 
LVL 48

Accepted Solution

by:
Tintin earned 200 total points
ID: 21853063
Your working directory is C:/Inetpub//cgi-bin

0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question