Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I experience issue with the following code (MacOSX Sierra, Perl 5.24.0, librairies supplied via Homebrew, shell is zsh)

#!/Users/landry/perl5/perlbrew/perls/stable/bin/perl use strict; my @args= ("gcc","-o /usr/local/bin/dcraw -O4","/Users/landry/Desk +top/dcraw.c","-I/usr/local/include -L/usr/local/lib -lm -ljasper -ljp +eg -llcms2"); system(@args);

Running this script lead to the following error:

/Users/landry/Desktop/dcraw.c:77:10: fatal error: 'jasper/jasper.h' file not found

Running the gcc command directly to the shell does not produce any error. I do not have any clue why running the command through 'system' does not seems find the library. Thanks for your suggestions.

Replies are listed 'Best First'.
Re: Issue with 'system'
by Corion (Patriarch) on Oct 15, 2016 at 18:01 UTC

    Your command is a mix of single and multiple options. You will need to pass all parameters as separate list items instead of munging some into a long string and some alonw:

    # "-o /usr/local/bin/dcraw -O4" needs to be a separated list: my @args= ("gcc","-o", "/usr/local/bin/dcraw","-O4","/Users/landry +/Desktop/dcraw.c","-I/usr/local/include", "-L/usr/local/lib","-lm","- +ljasper","-ljpeg", "-llcms2"); system(@args) == 0 or die "Couldn't launch [@args]: $? / $!";

    I assume that the current working directory is the same as when testing through the shell.

      Thanks for pointing this solution. Does solve the issue.

Re: Issue with 'system'
by shmem (Chancellor) on Oct 15, 2016 at 18:55 UTC

    What Corion says. TIMTOWTDI:

    system("@args"); # makes @args into a string
    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      Note that system("@args") will cause a shell to be invoked to process the string. system(@args) will exec (or spawn) the specified program without using an intermediate shell.

      This work as well as the first reply. Learned something. Thanks.