CVS access via PERL

Discussion in 'Perl Misc' started by Holger Biebinger, Apr 19, 2004.

  1. Hi NG,
    I would like to access a CVS Server which provides pserverv access. I
    tried to access via
    cvs [Directory here] login
    After that i get a login prompt. Can I enter my password with PERL? I am
    a beginner in using the PERL language.
    I would appreciate any help.

    Holger
    Holger Biebinger, Apr 19, 2004
    #1
    1. Advertising

  2. Holger Biebinger

    Paul Lalli Guest

    On Mon, 19 Apr 2004, Holger Biebinger wrote:

    > Hi NG,
    > I would like to access a CVS Server which provides pserverv access. I
    > tried to access via
    > cvs [Directory here] login
    > After that i get a login prompt. Can I enter my password with PERL? I am
    > a beginner in using the PERL language.
    > I would appreciate any help.
    >


    The first help you'll get is a bunch of people telling you the language's
    name is "Perl" not "PERL". Please follow that advice.

    The second piece of advice I'll give is that you may want to check out the
    CVS module at http://search.cpan.org/~rsoliv/Cvs-0.06/lib/Cvs.pm

    The third piece of advice is that you should read the Posting Guidelines
    which are posted regularly to the group. Specifically in this case,
    please pay attention to the bit that tells you to "Speak Perl, not
    English". That is, what do you mean when you said "I tried to access via
    cvs [Directory here] login". Did you execute a system command? Are you
    redirecting your Perl script to or from the CVS command? Show us what
    you're doing.

    Paul Lalli
    Paul Lalli, Apr 19, 2004
    #2
    1. Advertising

  3. Hi,

    Paul Lalli wrote:

    > On Mon, 19 Apr 2004, Holger Biebinger wrote:
    >
    >>I would like to access a CVS Server which provides pserverv access. I
    >>tried to access via
    >>cvs [Directory here] login
    >>After that i get a login prompt. Can I enter my password with PERL? I am
    >>a beginner in using the PERL language.
    >>I would appreciate any help.
    >>

    >
    > The first help you'll get is a bunch of people telling you the language's
    > name is "Perl" not "PERL". Please follow that advice.
    >

    Ok thanks. I will follow that advice.

    > The second piece of advice I'll give is that you may want to check out the
    > CVS module at http://search.cpan.org/~rsoliv/Cvs-0.06/lib/Cvs.pm
    >

    I will have a look at it. Thanks for that hint. :)

    > The third piece of advice is that you should read the Posting Guidelines
    > which are posted regularly to the group. Specifically in this case,
    > please pay attention to the bit that tells you to "Speak Perl, not
    > English". That is, what do you mean when you said "I tried to access via
    > cvs [Directory here] login". Did you execute a system command? Are you
    > redirecting your Perl script to or from the CVS command? Show us what
    > you're doing.
    >


    Ok, let me try to speak Perl. I'm afraid I have quite a bad accent ;-) I
    have a config file with the CVS access data and i want to connect to the
    cvs server for a checkout:

    test.cfg (the config file)
    # CVS Variables
    CVS_SERVER = 192.168.0.1
    CVS_DIR = /usr/cvs
    CVS_RSH = pserver

    CVS_USERNAME = holger
    CVS_PASSWORD = test

    # webEdition Revision Variables
    PROJECT = testproject
    RELEASE = REL_0_1

    test.pl
    #!/usr/bin/perl -w

    # I don't exactly know if I need all those packages
    use File::Find;
    use File::path;
    use File::Basename;
    use File::Copy;
    use File::Spec;
    use File::DosGlob 'glob'; # TinyPerl only seems to work with DosGlob :-/
    use FileHandle;
    use Getopt::Std;
    use Config;

    %config = (
    );

    $scriptbase = dirname($0);
    $configfile = "$scriptbase/testfile.cfg" unless $configfile;
    parse_cfg($configfile);

    my $cvs ="cvs -d
    :$config{'CVS_RSH'}:$config{'CVS_USERNAME'}"."@"."$config{'CVS_SERVER'}:"."$config{'CVS_DIR'}";
    my $release = $config{'RELEASE'};
    my $project = $config{'PROJECT'};
    my $checkoutdir = $config{'CHECKOUTDIR'};

    system "$cvs login";
    #how can I enter the password?
    system "$cvs co $project";

    sub parse_cfg {
    my $inifile = shift;
    my ($var, $val);

    open(CONFIG, $configfile) || die ("Error opening $configfile !");
    print("Config File opened!\n");
    while(<CONFIG>) {
    next if /^\s*#/;
    next unless /(\w+)\s*=\s*(.+)/;

    ($var, $val) = ($1, $2);

    $config{$var} = $val;
    }
    close(CONFIG);
    }

    Thanks again.
    Holger
    Holger Biebinger, Apr 19, 2004
    #3
  4. Holger Biebinger

    Paul Lalli Guest

    On Mon, 19 Apr 2004, Holger Biebinger wrote:

    > Ok, let me try to speak Perl. I'm afraid I have quite a bad accent ;-) I
    > have a config file with the CVS access data and i want to connect to the
    > cvs server for a checkout:
    >
    > test.pl
    > #!/usr/bin/perl -w
    >
    > # I don't exactly know if I need all those packages
    > use File::Find;
    > use File::path;
    > use File::Basename;
    > use File::Copy;
    > use File::Spec;
    > use File::DosGlob 'glob'; # TinyPerl only seems to work with DosGlob :-/
    > use FileHandle;
    > use Getopt::Std;
    > use Config;


    The only one I see you using here are File::Basename (for dirname()). I
    would recommend getting rid of the rest (and if the interpreter gives you
    an error, then you know you should add it back. :) )

    >
    > %config = (
    > );
    >
    > $scriptbase = dirname($0);
    > $configfile = "$scriptbase/testfile.cfg" unless $configfile;
    > parse_cfg($configfile);
    >
    > my $cvs ="cvs -d
    > :$config{'CVS_RSH'}:$config{'CVS_USERNAME'}"."@"."$config{'CVS_SERVER'}:"."$config{'CVS_DIR'}";


    Gahh. That looks rather messy. You might want to take advantage of the
    hashkey property of barewords, not to mention escaping @ characters:

    my $cvs ="cvs -d :$config{CVS_RSH}:$config{CVS_USERNAME}\@$config{CVS_SERVER}:$config{CVS_DIR}";

    Well. It's mildly better anyway.

    > my $release = $config{'RELEASE'};
    > my $project = $config{'PROJECT'};
    > my $checkoutdir = $config{'CHECKOUTDIR'};
    >
    > system "$cvs login";
    > #how can I enter the password?
    > system "$cvs co $project";
    >


    Okay. Now I understand. The simple answer is that you can't, at least not
    like this. What you're trying to do is called "bidirectional interprocess
    communication". That is, both getting input from and sending output to a
    process. This is more complicated than you might imagine. For more
    details, read:
    perldoc -q pipe

    That documentation will refer you to the IPC::Open2 module. However,
    since you are trying to do something very specific with your bidirectional
    pipe - something that many people before you have wanted to do - there
    already exists a module specifically for it. I therefore refer you back
    to the CVS module from CPAN that I posted in my previous message.


    Paul Lalli

    > sub parse_cfg {
    > my $inifile = shift;
    > my ($var, $val);
    >
    > open(CONFIG, $configfile) || die ("Error opening $configfile !");
    > print("Config File opened!\n");
    > while(<CONFIG>) {
    > next if /^\s*#/;
    > next unless /(\w+)\s*=\s*(.+)/;
    >
    > ($var, $val) = ($1, $2);
    >
    > $config{$var} = $val;
    > }
    > close(CONFIG);
    > }
    >
    > Thanks again.
    > Holger
    >
    >
    Paul Lalli, Apr 19, 2004
    #4
  5. Hi,

    Paul Lalli wrote:

    > On Mon, 19 Apr 2004, Holger Biebinger wrote:
    >
    >
    >>Ok, let me try to speak Perl. I'm afraid I have quite a bad accent ;-) I
    >>have a config file with the CVS access data and i want to connect to the
    >>cvs server for a checkout:
    >>
    >>test.pl
    >>#!/usr/bin/perl -w
    >>
    >># I don't exactly know if I need all those packages
    >>use File::Find;
    >>use File::path;
    >>use File::Basename;
    >>use File::Copy;
    >>use File::Spec;
    >>use File::DosGlob 'glob'; # TinyPerl only seems to work with DosGlob :-/
    >>use FileHandle;
    >>use Getopt::Std;
    >>use Config;

    >
    >
    > The only one I see you using here are File::Basename (for dirname()). I
    > would recommend getting rid of the rest (and if the interpreter gives you
    > an error, then you know you should add it back. :) )
    >
    >

    Ok you were right. It was the only one needed.

    >>%config = (
    >>);
    >>
    >>$scriptbase = dirname($0);
    >>$configfile = "$scriptbase/testfile.cfg" unless $configfile;
    >>parse_cfg($configfile);
    >>
    >>my $cvs ="cvs -d
    >>:$config{'CVS_RSH'}:$config{'CVS_USERNAME'}"."@"."$config{'CVS_SERVER'}:"."$config{'CVS_DIR'}";

    >
    >
    > Gahh. That looks rather messy. You might want to take advantage of the
    > hashkey property of barewords, not to mention escaping @ characters:
    >
    > my $cvs ="cvs -d :$config{CVS_RSH}:$config{CVS_USERNAME}\@$config{CVS_SERVER}:$config{CVS_DIR}";
    >
    > Well. It's mildly better anyway.
    >

    Really, its better. Thanks for that hint.

    >
    >>my $release = $config{'RELEASE'};
    >>my $project = $config{'PROJECT'};
    >>my $checkoutdir = $config{'CHECKOUTDIR'};
    >>
    >>system "$cvs login";
    >>#how can I enter the password?
    >>system "$cvs co $project";
    >>

    >
    >
    > Okay. Now I understand. The simple answer is that you can't, at least not
    > like this. What you're trying to do is called "bidirectional interprocess
    > communication". That is, both getting input from and sending output to a
    > process. This is more complicated than you might imagine. For more
    > details, read:
    > perldoc -q pipe
    >

    OK. it is not quite easy ;-) It was the humble try of a beginner.

    > That documentation will refer you to the IPC::Open2 module. However,
    > since you are trying to do something very specific with your bidirectional
    > pipe - something that many people before you have wanted to do - there
    > already exists a module specifically for it. I therefore refer you back
    > to the CVS module from CPAN that I posted in my previous message.
    >

    I tried it out and it seems to work for my purposes. Great. Next time I
    will first have a look if anyone else has already done the work for me
    ;-) Now I know where to search.

    Holger
    Holger Biebinger, Apr 20, 2004
    #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. ddog
    Replies:
    3
    Views:
    580
    Jason Whaley
    Aug 4, 2007
  2. Replies:
    1
    Views:
    586
    GArlington
    Aug 31, 2007
  3. David Ross
    Replies:
    5
    Views:
    144
    Nicholas Van Weerdenburg
    Dec 5, 2004
  4. Chris Weiss

    How to capture output of CVS via Perl?

    Chris Weiss, Oct 8, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    178
    Tad McClellan
    Oct 9, 2004
  5. Chris Weiss

    How to capture output of CVS via Perl?

    Chris Weiss, Oct 8, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    92
    John Bokma
    Oct 8, 2004
Loading...

Share This Page