When executing external commands in perl, if there are no special shell characters perl executes the command directly, but there is no /usr/bin/command so it fails. You can see this if you try to strace the script. If there are special characters like redirections (I've added apostrophe in this case) perl will run it using /bin/sh instead of directly.
Regarding best practice, I don't know. Not sure what debian's coding style dictates. Though it is interesting to check what other perl script do instead of calling which. Checking directly for /usr/bin/file could be considered more secure in case someone has another 'file' in their PATH, but will make it harder to check against different versions of 'file' (if any exists). You could also instead check the return value of open(READER, .. ,"file") to see if it fails. Other options might be to use File::Which or File:LibMagic modules and have a more perl-y solution, but it will add dependencies for the package. Not sure what the best solution is... HTH, On Mon, 27 May 2024 at 05:27, Charles Plessy <[email protected]> wrote: > Le Sun, May 26, 2024 at 05:35:28PM +0300, Yair Yarom a écrit : > > > > The function MagicMimetype always fails because the `command -v file` > isn't > > executed inside a shell (rather, perl searches for the "command" binary, > and > > fails to find it). > > Thanks Yair for the patch. I confirm it works. > > Can you give me a longer explanation why it works? > > In any case, I wonder if just searching for /usr/bin/file would make > more sense. What do you think about it? > > Have a nice day, > > Charles > -- /| | \/ | Yair Yarom | System Group (DevOps) [] | The Rachel and Selim Benin School [] /\ | of Computer Science and Engineering []//\\/ | The Hebrew University of Jerusalem [// \\ | T +972-2-5494522 | F +972-2-5494522 // \ | [email protected] // |

