Home > Net >  running gam command inside perl script
running gam command inside perl script

Time:09-17

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");

CodePudding user response:

You should always begin your programs with use strict; and use warnings;. This will catch and report many issues with your code.

For this particular code, it may just be that the interpolation of @co inside your string is failing (causing the gam command to fail). Or it may be that gam is not on your path and so the exec itself is failing.

CodePudding user response:

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);
  •  Tags:  
  • perl
  • Related