The program does not work at all with file with long path.
So I need to read a file manually and pipe it to the program's stdin.
const path = "C:\\the long path directory example\\" +
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam\\" +
"the example image — with long name — Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.jpg";
const exiftool = spawn("exiftool", [path]); // const exiftool = spawn(`exiftool.exe "${path}"`, {shell: true});
const log = data => console.log(data.toString("utf8"));
exiftool.stdout.on("data", log);
exiftool.stderr.on("data", log); // "Error: File not found - ..."
console.log(fs.readFileSync(path).byteLength, "bytes"); // read successfully — "9060 bytes"
const cmd = spawn(`type "${path}" | exiftool.exe -`, {shell: true}); // it also works
cmd.stdout.on("data", log); // prints the result
Windows 10 (with enabled NTFS long paths policy), exiftool 12.2.7.0.
UPD: Well, it was already reported before: https://exiftool.org/forum/index.php?topic=11539
this is rather likely a limitation of Perl, see https://exiftool.org/forum/index.php?topic=11034.0