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


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

Any ideas what the problem might be?

Yes. Only an idea though.

The PATH environment variable differs between the systems when running system from perl. Perhaps when executing in the Docker container the 'command' binary can't be found because it's not looking in the right place.

system("echo \$PATH");

Replies are listed 'Best First'.
Re^2: Can't exec "command": No such file or directory error
by haukex (Archbishop) on Dec 14, 2022 at 22:36 UTC
    the 'command' binary

    nysus wrote 'which command reports: "command: shell built-in command"' which leads me to think that there may not be a command binary at all.

      Indeed. find command turned up /usr/bin/command on macos. I can not find any such animal on alpine. I'm wondering if it's in a separate alpine package.

      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.

      $PM = "Perl Monk's";
      $MC = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar Parson";
      $nysus = $PM . ' ' . $MC;
      Click here if you love Perl Monks

        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.