Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: system call error

by marto (Cardinal)
on Apr 11, 2020 at 12:57 UTC ( [id://11115375]=note: print w/replies, xml ) Need Help??


in reply to system call error

my @elf_files = system("ls"); #or backtiks

Your code doesn't do what you think it does. See Why can't I get the output of a command with system()?. Tutorials->Getting Started with Perl/Basic debugging checklist. Basic debugging could have simply been printing the values before you used them. In the chatterbox Corion provided you with a solution reporting the command actually being run on failure.

Adding:

use strict; use warnings;

generates:

Use of uninitialized value in concatenation (.) or string at ./derp.pl + line 8. readelf: Warning: Nothing to do.

Rather than just:

readelf: Warning: Nothing to do.

You code doesn't cater for all use cases, e.g. if there's a sub directory:

readelf: Error: 'ffmpeg_sources' is not an ordinary file

You should consider not shelling out and just using perl to handle this, opendir, readdir, grep, or modules like Path::Tiny which provide simpler ways of doing this.

Update: for completeness, the only line of code offered in the chatterbox was:

system("readelf -sW $var | awk '{print \$NF}'");

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11115375]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-24 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found