Process

Neutralino's OS API (execCommand method): https://neutralino.js.org/docs/api/os#osexeccommandcommand-options

Static class

Process.run(command, options)

import { Process } from '@empathize/framework';

// Executes 'rm -rf "my_folder"'
Process.run('rm -rf "my_folder"');

// Executes 'cd "my_folder" && SOME_ENV_VARIABLE="example value" rm -rf "my_folder"'
Process.run('rm -rf "my_file.txt"', {
    cwd: 'my_folder',
    env: {
        SOME_ENV_VARIABLE: 'example value'
    }
});

Process.kill(id, forced)

import { Process } from '@empathize/framework';

// SIGTERM (-15)
Process.kill(1293);

// SIGKILL (-9)
Process.kill(1293, true);

Object

process.finish(callback)

Specify callback that will be called when the process will be closed

import { Process } from '@empathize/framework';

Process.run('some_command').then((process) => {
    process.finish((process) => {
        console.log(`Process with id ${process.id} was closed`);
    });
});

process.output(callback)

Specify callback that will be called when the process will write some output

import { Process } from '@empathize/framework';

Process.run('some_command').then((process) => {
    process.output((output, process) => {
        console.log(output);
    });
});

process.kill(forced)

import { Process } from '@empathize/framework';

Process.run('some_command').then((process) => {
    // Kill this process after 5 seconds with SIGTERM (-15)
    setTimeout(() => {
        process.kill();
    }, 5000);
});

process.running()

import { Process } from '@empathize/framework';

Process.run('some_command').then((process) => {
    setInterval(async () => {
        const running = await process.running();
        
        if (!running)
            console.log('Hey! This process was stopped!');
    }, 3000);
});

Last updated