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

Hi, I am trying to change my directory to a clearcase vob and run some clearcase commands in that directory. I am unable to change my directory as it complains there is no such directory (But the directory exists :(). Can some one tell me what am I doing wrong? Here is the code:
#!/usr/bin/perl use strict; use warnings; use Cwd; use Tie::File; use Fcntl; #Variable Declaration my $request="no"; my $dir=getcwd; my $md_dir=''; my @files=""; my $vp_file="vp_file"; my $view_tag = $ENV{'VIEW_TAG'}; my @data; print "\n\n Checking to see if you have any checkout files...\n "; if ( -z "/$view_tag/app_hwt/3126" || ! -e "/$view_tag/app_hwt/3126" ) { $md_dir='medium_duty'; } else { $md_dir='3126'; } ##################################### #HERE IS WHERE ITS GIVING ME THE ERROR ##################################### system ("cd /$view_tag/lib_engine/hwt"); system("cleartool lsco -cview -r -s > /$view_tag/lib_engine/hwt/co_fi +le"); system ("cd /$view_tag/app_hwt/$md_dir"); system("cleartool lsco -cview -r -s >> /$view_tag/lib_engine/hwt/co_f +ile"); if ( ! -z "/$view_tag/lib_engine/hwt/co_file" ) { print "\n ***You have check out files.*** "; print " Please either check them in or out before running thi +s program again. \n"; print " Do you want to list chkout files y/n? [deflt no]: "; chomp($request = <>); if ( $request =~ /[Yy]/ ) { print "\n"; open(FILE, "/$view_tag/lib_engine/hwt/$co_file") || die "Cann +ot open co_file: $!\n"; print "\n"; } unlink "/$view_tag/lib_engine/hwt/co_file"; die("$!"); } else { print "\n\n Now Checking to see if you have any view private fil +es...\n "; if ( ! -e "/$view_tag/lib_engine/hwt/co_file" ) { unlink "/$view_tag/lib_engine/hwt/co_file"; } `cleartool lsprivate -other -s > vp_temp`; my $temp_file="vp_temp"; open(FILE,"vp_temp") || die "Cannot open vp_temp:$!\n"; close(FILE); open(OUTPUT,">>vp_file"); tie (@data,'Tie::File',$temp_file, mode=>O_RDWR) or die "Can't tie + to $temp_file:$^E\n"; (tied @data)->defer; foreach(@data) { # see ex.pl @files=grep(/\.c$/ || /\.h$/ || /\.a32$/ || /\.cfg$/ || /^Make +file_\..*$/ ,@data); } print OUTPUT @files; unlink "vp_temp"; if ( ! -z "vp_file" ) { print "\n You have view private files: \n "; open(FILE, "vp_file") || die "Cannot open vp_file: $!\n"; print " \n\n "; unlink "vp_file"; } else { print "\n Good Job! You have no view private files... \n\n "; if ( ! -e "vp_file" ) { unlink "vp_file"; } } }
Thanks in advance

Replies are listed 'Best First'.
Re: Changing directory to a clearcase vob doesnot work please help
by Fletch (Bishop) on Jan 28, 2008 at 20:42 UTC

    You're running your shell's builtin cd command in a subshell which then exits and returns control to your program. This quite understandably isn't going to do anything useful.

    You need to go read the question " I {changed directory, modified my environment} in a perl script. How come the change disappeared when I exited the script? How do I get my changes to be visible?" in perlfaq8, and the documentation for chdir.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Even chdir does not work...is there something I am missing?
Re: Changing directory to a clearcase vob doesnot work please help
by jdporter (Paladin) on Jan 28, 2008 at 21:15 UTC

    More specifically (from what Fletch said), you could this:

    system("cd /$view_tag/lib_engine/hwt ; cleartool lsco -cview -r -s > + /$view_tag/lib_engine/hwt/co_file"); system("cd /$view_tag/app_hwt/$md_dir ; cleartool lsco -cview -r -s > +> /$view_tag/lib_engine/hwt/co_file");
      Based on the response I got I just tried some thing like this:
      #!/usr/bin/perl use strict; use warnings; use Cwd; my $view_tag = $ENV{'VIEW_TAG'}; my $md_dir=''; system("cd /$view_tag/lib_engine/hwt ; cleartool lsco -cview -r -s > +/$view_tag/lib_engine/hwt/co_file"); system("cd /$view_tag/app_hwt/$md_dir ; cleartool lsco -cview -r -s > +> /$view_tag/lib_engine/hwt/co_file");
      But still it complains the file name directory name volume label syntax is incorrect Thanks
        Fletch is on the right track with this. First, everything you do with clearcase inside some view tag has to be 'exec'd out'.
        So here is one complex way of getting around clearcase problem:
        Have perl generate a simple 3 liner sh script, something like,
        #!/bin/sh /pathtocleartool/cleartool setcs -tag VIEWNAME CONFIGSPECPATH ...do things here...

        Then, in your perl script, /cleartoolpath/cleartool setview -exec $shellscriptname VIEWNAME

        This spawns a new process for each thing you do using clearcase exec, which is the documentation you need to look through.

        I often find it helpful to print the string out, debug-style, and try executing it manually. Sometimes, just seeing it, the problem pops right out. E.g.

        my $cmd = "cd /$view_tag/lib_engine/hwt ; cleartool lsco -cview -r -s + > /$view_tag/lib_engine/hwt/co_file"; warn "cmd:\n$cmd\n"; # what exactly are we going to try to execute? system $cmd;
        my $view_tag = $ENV{'VIEW_TAG'}; system("cd /$view_tag/lib_engine/hwt ;

        What's your viewroot?
        If you're using view extended pathnames then your views will be visible under (typically) /view/$VIEW_TAG rather than /$VIEW_TAG

Re: Changing directory to a clearcase vob doesnot work please help
by Zen (Deacon) on Jan 29, 2008 at 17:06 UTC
    Yes, doing this from the windows side is somewhat more difficult because of the static vs dynamic view thing with CC for Windows. I would recommend not doing this on windows, but if you simply must, then you should first try out a chdir('some dir in your view'). This should be no problem in a window where your static view is set up. If that doesn't work, please follow my example for an exec of a script that perhaps does a desc of an element or something trivial.

    To summarize, CC is tricky but even more so, and you're going to have to try doing very simple things before you throw big scripts at it. Please look at the -exec docs.