#spawn in flows

2 messages · Page 1 of 1 (latest)

loud coral
#

Hi everyone,
In a flow with the component script, i try to launch another process...but without any success
below 2 of my try, If anyone have an idea....

try one :
module.exports = async function(data) {
import {
spawnSync
} from 'node:child_process';

console.log("########################################################");

const ruby_bin = '/usr/bin/ruby';
const script_file = "/opt/nodejs/bdc/scripts/bdc_rb_back_cmd.rb"
const script_arg_cmd = "gen_numero_bdc";
const script_arg_data_b64 = Buffer.from(JSON.stringify(data), 'UTF8').toString('base64');

const result = spawnSync(
ruby_bin,
[script_file, script_arg_cmd, script_arg_data_b64],
{
stdio: ['ignore', 'pipe', 'inherit'],
encoding: 'utf-8',
shell: true,
}
);

console.log("#######");
console.log(result);
console.log("#######");
console.log(result.stdout);
console.log("#######");
console.log(result.stderr);
console.log("#######");

 return data;

}

try 2 :

module.exports = async function(data) {
const ruby_bin = '/usr/bin/ruby';

let base64data = Buffer.from(JSON.stringify(data), 'UTF8').toString('base64');

const child_process = require('child_process');
const script_file="/opt/nodejs/bdc/scripts/bdc_rb_back_cmd.rb"
let cmd = ruby_bin + " " + script_file+ " gen_numero_bdc "+ base64data;
console.log("invoking : " + cmd);
let ls_process = child_process.exec(cmd);
 return {};

}

sub part of this code was succesfuly tested in file launched by nodejs, but it dont work in directus ☹️

any comment are welcome

warm sky
#

I don't think the vm2 sandbox used for scripts in flows allows for such operations 🤔 you could try allowing modules like child_process question is how much use that would be inside the sandbox without access to the filesystem etc. This logic is probably better housed in a custom hook or endpoint which are not run within a sandbox