Search code examples
perl

running gam command inside perl script


Im new to perl and trying to run the below advanced gam command within a simple perl script but it will not print the output to screen no matter what I use - what am I doing wrong ?

#!/usr/bin/perl

#exec ("ls -l");

chdir '/home/ted/bin/gamadv-xtd3';

#exec ("gam user [email protected] show contacts emailmatchpattern [email protected]  fields email");
#system "gam user [email protected] show contacts emailmatchpattern [email protected]  fields email";
exec ("gam user [email protected] show contacts emailmatchpattern [email protected] fields email");

Solution

  • Following code snippet demonstrates how you should use system() call in perl.

    Please see: system, Quote and Quote-like Operators

    use strict;
    use warnings;
    
    my $cmd  = $ENV{HOME} . '/bin/gamadv-xtd3';
    my @args = qw/gam user [email protected] show contacts emailmatchpattern [email protected] fields email/;
    
    system($cdm,@args);