llancet has asked for the wisdom of the Perl Monks concerning the following question:

Once I run a script, the getcwd() in Cwd package fails to give current directory. Moreover, I tried system('pwd'), it also fails. Why and how could this phenomenon happen?

When it happened, I was running the script at a remote machine through ssh.

thanks...

Replies are listed 'Best First'.
Re: getcwd failed
by moritz (Cardinal) on Apr 29, 2010 at 08:29 UTC
    I tried system('pwd'), it also fails.
    In what way did it fail?
    Why and how could this phenomenon happen?

    One possible reason is that the current directory was deleted concurrently by another process.

Re: getcwd failed
by Khen1950fx (Canon) on Apr 29, 2010 at 09:16 UTC
    I tried a simple Cwd script with a simple Net::SSH::Perl script. Worked for me:
    #!/usr/bin/perl use strict; use warnings; use Cwd; my $dir = getcwd; print $dir, "\n";
    The Net::SSH::Perl script:
    #!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; use constant { HOST => 'localhost', USER => 'user', PASSWORD => 'password', }; my $ssh = Net::SSH::Perl->new( HOST, port => 22 || 'ssh', protocol => 2, debug => 1, ); $ssh->login(USER, PASSWORD); my ($stdout, $stderr, $exit) = $ssh->cmd( 'perl /root/Desktop/cwd.pl'); print $stdout, "\n"; exit;
Re: getcwd failed
by rovf (Priest) on Apr 29, 2010 at 09:17 UTC

    You could try system('readlink -f .') or, if your application is interactive, shell out with system('bash') and have a look.

    -- 
    Ronald Fischer <ynnor@mm.st>
      I cannot reproduce the issue. After I exited the remote shell and re-login, the script works fine...