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.


In reply to Re^4: Can't exec "command": No such file or directory error by haukex
in thread Can't exec "command": No such file or directory error by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.