🚀
Empathize
  • Introduction
  • Installation
  • API
    • Paths API
      • Directories
      • Paths
    • Filesystem API
      • Filesystem
    • Windows API
      • Windows
    • OS API
      • Process
      • Tray
      • IPC
      • Notification
      • Archive
      • Package
    • Network API
      • fetch
      • Domain
      • Downloader
    • Async API
      • promisify
    • Meta classes
      • Cache
      • Configs
      • Debug
  • Building application
Powered by GitBook
On this page
  • Static class
  • Process.run(command, options)
  • Process.kill(id, forced)
  • Object
  • process.finish(callback)
  • process.output(callback)
  • process.kill(forced)
  • process.running()
  1. API
  2. OS API

Process

PreviousOS APINextTray

Last updated 3 years ago

Neutralino's OS API (execCommand method):

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);
});
https://neutralino.js.org/docs/api/os#osexeccommandcommand-options