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

CWD question

Status
Not open for further replies.
Dec 5, 2003
9
0
0
NO
Where is the cwd actually set ?
When I run a perl-script from a webpage with the following directory structure

g:\
that is supposed to list the content of the folder g:\
it instead listst the content of C:\WINNT

use Cwd;
$path = getcwd;
print "$path\n";

returns c:\winnt - and I would want it to return g:\
I know I can just hardcode the script to use the path I want, but I thought I'd ask you guys first...

here is the entire script as written by default :

#!/usr/bin/perl
print "Content-type: text/html\n\n";

open (STDERR, ">&STDOUT");

print "Dateien im aktuellem Verzeichnis . sind: \n";
opendir DIESESVERZEICHNIS, "." or die "Kann Verzeichnis nicht ffnen: $!";
@alledateien = readdir DIESESVERZEICHNIS;
closedir DIESESVERZEICHNIS;
print "@alledateien\n";
exit(0);

"." should refer to the users homedir, but instead lists c:\winnt ... any idea why ??
 
PugTheBlack,

Most groupers here read English, I only lived 4 storeys over an Irish Pub in Essen for 9 months, and can make some sense of this. It's an idea to "Anglify" your scripts before posting, as more people will be qualified to help

#!/usr/bin/perl
print "Content-type: text/html\n\n";

open (STDERR, ">&STDOUT");

print "Dateien im aktuellem Verzeichnis . sind: \n";
opendir DIESESVERZEICHNIS, "." or die "Kann Verzeichnis nicht ffnen: $!";
@alledateien = readdir DIESESVERZEICHNIS;
closedir DIESESVERZEICHNIS;
print "@alledateien\n";
exit(0);

"." should refer to the users homedir, but instead lists c:\winnt ... any idea why ??

In English
print "Files in this directory are\n"; #rough xlation
openddir THISDIR, "." or die "Can't open Directory $!";
@allfiles=readdir THISDIR;
closedir THISDIR;
print "@allfiles\n";

Your problem;
"." refers to the current directory ".." means one up
HTH
--Paul
 
well... I hardly understand what the script says myself as I'm not German, but the words are not really important in this context... What you call the DIRNAME, and EXPR variables + the error msg ?? Of course I could translate them, but the problem has nothing to do with the german text

And why in your opinion would the "." not list the contents of the current folder g:\ but rather c:\winnt then ?

That is what I can't understand
 
btw... tried the fix and put ".." instead of "." and ended up getting a listing of absolutely nothing.

I have made a manual fix by hardcoding the adress into the script, but that doesn't really make the script very versatile does it ?
 
Pug,
Code:
#!/usr/bin/perl 
print "Content-type: text/html\n\n";
use Cwd;
$path = getcwd;
print "$path\n";
open (STDERR, ">&STDOUT");
print "Dateien im aktuellem Verzeichnis . sind: \n";
opendir DIESESVERZEICHNIS, "." or die "Kann Verzeichnis nicht ffnen: $!";
@alledateien = readdir DIESESVERZEICHNIS;
closedir DIESESVERZEICHNIS;
foreach (@alledateien) {
  print "$_\n";
 }
exit(0);
I ran the script above, in 'My Documents' directory, adn it ran as expected. Is there a possibility that you have another similarly named script, and are accessing it by mistake?

--Paul
 
No, and the weird thing is that I am running it on several other servers and it runs correctly on all of them .. :-\

We did have the same problem on another server for a while, but for some reason it just corrected itself...

But back to the BASE question here, the getcwd call returns c:\winnt, what defines the cwd ? Is the cwd the actual directory you run the script from ( it can't be in my case ) or is it defined somewhere else ?

Thx alot for trying to help Paul, much appreciated :)





 
Try

$mycwd=cwd; #it's slower, but might be more accurate

--Paul

"It just corrected itself", sounds like there's a possibility that someone else is changing the configuration of the servers
 
will try the $mycwd=cwd; option too...

well we were 2 ppl working on the problem at the time, but none of us really did anything ( atleast not that we can remember :p )
 
You said you "run a perl-script from a webpage".
Could it be your web server setting the "current working directory" before calling your script ?
Then it would be a web server configuration problem.

--------------------
"When all else has failed, read the manuals."

Denis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top