http://qs321.pair.com?node_id=11148877


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.