Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^4: Can't exec "command": No such file or directory error

by haukex (Archbishop)
on Dec 14, 2022 at 23:20 UTC ( #11148877=note: print w/replies, xml ) Need Help??


in reply to Re^3: Can't exec "command": No such file or directory error
in thread Can't exec "command": No such file or directory error

What's weird is if I do command task on alpine directly on the command line, it runs just fine. It's only with perl I seem to have the problem.

What you type at the command line gets interpreted by whatever shell you have running at that moment. The shell may recognise built-in commands that don't exist as binaries in the filesystem. In some cases, commands can be both built-ins and exist as binaries in the file system, with (AFAIK) the built-ins taking precedence over the binaries in the PATH (again, I'm only talking about commands typed into the shell here). For example, when you type echo in bash, the shell will use its built-in instead of calling /bin/echo. You can get the binary if you explicitly run /bin/echo.

But if you explicitly want to access the shell built-in from Perl, the tricky thing is that Perl's system and similar functions may or may not run the command in a shell (/bin/sh!) for you depending on what arguments you give them. So, you'll need to be explicit about calling the shell, and the form I showed will prevent Perl from running a shell implicitly, and then we explicitly run zsh and give it a command to execute with -c, as if typed into the shell.

There is also a bit more about this in my node Calling External Commands More Safely.

A few edits for clarity.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2023-05-28 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?