Using clearcase command in perl script

Discussion in 'Perl Misc' started by mnt006@gmail.com, Dec 26, 2006.

  1. Guest

    Hi,
    I am having list of files in an array. Example.
    array[0]=/vobs/abc
    array[1]=/vobs/abc/foo1.c
    array[2]=/vobs/abc/foo2.c
    ........

    I want to perform clearcase check out command on this list of files.
    Can anyone suggest how to do this using perl?

    Thanks.
    , Dec 26, 2006
    #1
    1. Advertising

  2. Paul Lalli Guest

    wrote:

    > I am having list of files in an array. Example.
    > array[0]=/vobs/abc
    > array[1]=/vobs/abc/foo1.c
    > array[2]=/vobs/abc/foo2.c


    Please type real code, even in examples.

    my @array = qw(/vobs/abc /vobs/abc/foo1.c /vobs/abc/foo2.c);

    > I want to perform clearcase check out command on this list of files.
    > Can anyone suggest how to do this using perl?


    Perhaps you could describe how a "clearcase check out command" works or
    at least looks? Is it something that can only accept one filename as
    the argument? In that case, do something like:
    foreach my $file (@array) {
    system("clearcase_checkout_command", $file);
    }

    Is it something that accepts multiple file names, all specified on the
    command line? Then do something like:
    system("clearcase_checkout_command", @array);

    Until you tell us how to do the basic task, it's rather difficult to
    help you modify it for the real pursuit...

    Paul Lalli
    Paul Lalli, Dec 26, 2006
    #2
    1. Advertising

  3. Guest

    Thanks for responding.
    Cleartool makebranch command creates branch and checks out the file.
    It does take multiple files as input via command line.

    Actual command would look file following
    > cleartool mkbranch -nc my_branch_name /vobs/abc/foo1.c /vobs/abc/foo2.c


    "cleartool mkbranch -nc my_branch_name" would be constant string for
    all the files which are needed to be checked out.

    So from your suggestion I did try something like following.

    system("cleartool mkbranch -nc my_branch_name", @array);

    But due to some reason branch wasn't created.

    Thanks,

    Paul Lalli wrote:
    > wrote:
    >
    > > I am having list of files in an array. Example.
    > > array[0]=/vobs/abc
    > > array[1]=/vobs/abc/foo1.c
    > > array[2]=/vobs/abc/foo2.c

    >
    > Please type real code, even in examples.
    >
    > my @array = qw(/vobs/abc /vobs/abc/foo1.c /vobs/abc/foo2.c);
    >
    > > I want to perform clearcase check out command on this list of files.
    > > Can anyone suggest how to do this using perl?

    >
    > Perhaps you could describe how a "clearcase check out command" works or
    > at least looks? Is it something that can only accept one filename as
    > the argument? In that case, do something like:
    > foreach my $file (@array) {
    > system("clearcase_checkout_command", $file);
    > }
    >
    > Is it something that accepts multiple file names, all specified on the
    > command line? Then do something like:
    > system("clearcase_checkout_command", @array);
    >
    > Until you tell us how to do the basic task, it's rather difficult to
    > help you modify it for the real pursuit...
    >
    > Paul Lalli
    , Dec 26, 2006
    #3
  4. Paul Lalli Guest

    wrote:

    > Actual command would look file following
    > > cleartool mkbranch -nc my_branch_name /vobs/abc/foo1.c /vobs/abc/foo2.c

    >
    > "cleartool mkbranch -nc my_branch_name" would be constant string for
    > all the files which are needed to be checked out.
    >
    > So from your suggestion I did try something like following.
    >
    > system("cleartool mkbranch -nc my_branch_name", @array);
    >
    > But due to some reason branch wasn't created.


    "some reason"? Did you bother checking any of the error statuses? Did
    you check the return value of system()? The value of $? ? The value
    of $! ?

    Have you read the documentation for the function you're using? perldoc
    -f system

    system("cleartool", "mkbranch", "-nc", "my_branch_name", @array);
    will most likely produce better results. Read the aforementioned
    documentation to discover why.

    Paul Lalli
    Paul Lalli, Dec 26, 2006
    #4
  5. wrote:
    > Thanks for responding. Cleartool makebranch command creates branch and
    > checks out the file. It does take multiple files as input via command
    > line.
    >
    > Actual command would look file following
    >> cleartool mkbranch -nc my_branch_name /vobs/abc/foo1.c /vobs/abc/foo2.c

    > "cleartool mkbranch -nc my_branch_name" would be constant string for
    > all the files which are needed to be checked out.
    >
    > So from your suggestion I did try something like following.
    >
    > system("cleartool mkbranch -nc my_branch_name", @array);
    >
    > But due to some reason branch wasn't created.

    You do realize you initially asked "How to I checkout files" not "How do
    I call cleartool mkbranch" don't you?

    How about this:

    my $cmd = "cleartool mkbranch -nc my_branch_name" . @array;
    system $cmd

    Then run the script in the debugger and stop at the system command and
    "p $cmd" to see what exactly is in $cmd. Then copy and paste that to a
    command line thus executing the command outside of perl and seeing
    exactly what it did or did not do.

    Personally I tend to:

    my $cmd = "whatever command I'm doing";
    my @output = `$cmd 2>&1`;
    my $status = $?;
    chomp @output;

    if ($status ne 0) {
    <print some sort of error message like perhaps the contains of
    @output>
    }

    This way I can examine what $cmd contains before it's executed, get the
    command line output including stderr, get the status so I can check it
    and act accordingly if the status says the command failed.
    --
    Andrew DeFaria <http://defaria.com>
    Demons are a Ghouls best Friend.
    Andrew DeFaria, Dec 27, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony George
    Replies:
    1
    Views:
    580
    Jim Gibson
    Nov 14, 2003
  2. Maverick Ieong

    perl get crash when using ClearCase::CtCmd::exec

    Maverick Ieong, Nov 18, 2004, in forum: Perl Misc
    Replies:
    2
    Views:
    173
    Maverick Ieong
    Nov 18, 2004
  3. Maverick Ieong
    Replies:
    1
    Views:
    188
    Maverick Ieong
    Nov 24, 2004
  4. Replies:
    0
    Views:
    138
  5. sunil
    Replies:
    5
    Views:
    1,111
    Andrew DeFaria
    Jan 18, 2007
Loading...

Share This Page