I am trying to acess imagemagick from switch script but I am getting "command not found" error.
My goal is to convert psd to png and I am using exec from "child_process" alongside promisify from "util".
Since the logic of my script is complicated I created a dummy script with only 1 purpouse to convert a psd to png.
I made sure that the imagemagick is installed correctly on the machine.
I made sure that the exact same script is running properly on Windows environment.
The error occurs only under Mac(I am testing with M1 chip)
Things I tried that work properly
- Running exact same Switch script under windows
- Running independant(outside of Switch) node.js script with the same code(to make sure that my imagemagick is installed correctly on the machine)
- Running the command in terminal to double check that imagemagick is installed correctly
Here is the dummy script I am testing with:
Code: Select all
import { exec } from 'child_process';
import { promisify } from 'util';
async function jobArrived(s: Switch, flowElement: FlowElement, job: Job) {
const filePath = await job.get(AccessLevel.ReadOnly);
if(filePath.endsWith('.psd')) {
await flowElement.log(LogLevel.Info, 'Before convert');
const execAsync = promisify(exec);
const command = `magick convert "${filePath}" "${filePath.split('.')[0]}.png"`;
const { stdout, stderr } = await execAsync(command);
if (stderr) {
await flowElement.log(LogLevel.Error, `Error: ${stdout}`);
console.error('Error:', stderr);
} else {
await flowElement.log(LogLevel.Info, `Image converted successfully sending to ouput: ${stdout}`);
}
await flowElement.log(LogLevel.Info, 'After convert');
await job.sendToSingle();
} else {
await flowElement.log(LogLevel.Info, 'Sending converted file to output');
await job.sendToSingle();
}
}