Perl chdir doesn't work

╄→гoц情女王★ 提交于 2019-12-10 21:40:40

问题


A previous post might be useful: Perl system() call failed with return code 65280

Again, I've used this code many times, but it doesn't work here. I've moved all other perl instances from PATH.

Source:

$targetDir = "M\:\\bldforge_AOMS_DEV";
print ("targetDir=$targetDir\n");

chdir($targetDir) or die "Cant chdir to $dir $!";
$current_dir = `cd`;
print "\nCurrent dir = $current_dir\n" 

Output:

Z:\>ccperl test.pl
targetDir=M:\bldforge_AOMS_DEV

Current dir =

回答1:


To be sure you are indeed in a ClearCase view, I would use cleartool pwd:

$current_dir = `cleartool pwd`;

That will work even on Windows:

The cleartool pwd command lists the current working directory.
This command is intended for use in interactive cleartool and multitool sessions, and in batch files or shell scripts that simulate interactive sessions.




回答2:


You are mixing up pwd with cd. cd print only to STDERR, i.e. it succeeds silently.

My point is that cd is of no use in your case.




回答3:


To get the current working directory, you should be using Cwd's getdcwd function:

use Cwd;

my $current_dir = getdcwd 'M:';


来源:https://stackoverflow.com/questions/12006798/perl-chdir-doesnt-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!