frodo
frodo

Reputation: 1063

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

Upvotes: 1

Views: 99

Answers (2)

Polar Bear
Polar Bear

Reputation: 6798

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

Upvotes: 1

jhnc
jhnc

Reputation: 16761

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.

Upvotes: 1

Related Questions