Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface SystemWorker

Hierarchy

  • SystemWorker

Index

Constructors

Methods

Constructors

constructor

  • Creates a system worker (asynchronous mode). Use the system worker proxy to get the command output.

    Example 1: Do a simple CLI command

    var workerProxy = new SystemWorker( 'sh -c ls -la /Users/<user>/Desktop' );
    workerProxy.onerror = function ( event ) {
        console.log( event.type +': '+ event.data );
    }
    workerProxy.onmessage = function ( message ) {
        console.log( event.type +': '+ event.data );
    }
    workerProxy.onterminated = function ( event ) {
        console.log( event.type +': with exitStatus:'+ event.exitStatus );
    }
    // For testing purpose, wait for the worker to end. This makes it very similar to SystemWorker.exec().
    // In real application, keep working in parallels and do not pause the current thread
    workerProxy.wait();

    Example 2: Pass parameters, quotes and env variables options to the system worker

    var myFolder = new Folder( 'PROJECT' );
    var options = {
        parameters : { folder_ref : myFolder },
        quote : '"',
        variables : { ENV_VAR_1 : 'value1' }
    };
    var workerProxy = new SystemWorker( 'sh -c ls -la {file_ref}', options);

    Example 3: Run npm install in an emulated terminal

    var myFolder = new Folder( 'PROJECT' );
    var options = {
        parameters : { folder_ref : myFolder },
        quote : '"',
        emulateTerminal : true
    };
    var workerProxy = new SystemWorker( 'cmd /c npm install', options);
    warning

    The system worker can only launch executable applications. All shell instructions must be preceded by a command line interpreter like bash, sh or cmd depending of the OS.

    Parameters

    Returns WAKSystemWorkerProxy

    Returns a system worker proxy

  • Calls a system worker (asynchronous mode). Use the system worker proxy to get the result.

    Example 1: Do a simple CLI command

    var workerProxy = new SystemWorker( ['sh', '-c', 'ls -la /Users/<user>/Desktop'] );
    workerProxy.onerror = function ( event ) {
        console.log( event.type +': '+ event.data );
    }
    workerProxy.onmessage = function ( message ) {
        console.log( event.type +': '+ event.data );
    }
    workerProxy.onterminated = function ( event ) {
        console.log( event.type +': with exitStatus:'+ event.exitStatus );
    }
    // For testing purpose, wait for the worker to end. This makes it very similar to SystemWorker.exec().
    // In real application, keep working in parallels and do not pause the current thread
    workerProxy.wait();

    Example 2: Pass parameters, quotes and env variables options to the system worker

    var myFolder = new Folder( 'PROJECT' );
    var options = {
        parameters : { folder_ref : myFolder },
        quote : '"',
        variables : { ENV_VAR_1 : 'value1' }
    };
    var workerProxy = new SystemWorker( ['sh', '-c', 'ls -la {file_ref}'], options);

    Example 3: Run npm install in an emulated terminal

    var myFolder = new Folder( 'PROJECT' );
    var options = {
        parameters : { folder_ref : myFolder },
        quote : '"',
        emulateTerminal : true
    };
    var workerProxy = new SystemWorker( ['cmd', '/c', 'npm install'], options);
    warning

    The system worker can only launch executable applications. All shell instructions must be preceded by a command line interpreter like bash, sh or cmd depending of the OS.

    Parameters

    • cli: String[]

      Command line to execute

    • Optional options: WAKSystemWorkerOptions

      Describes command line options

    Returns WAKSystemWorkerProxy

    Returns a system worker proxy

Methods

exec

  • Runs the given command and waits for its response (synchronous mode).

    Example 1: Do a simple CLI command

    // Launch "sh" executable with "-c" parameter and "ls -la /Users/<user>/Desktop" as the action to do
    var workerResult = SystemWorker.exec( 'sh -c ls -la /Users/<user>/Desktop' );
    console.log(workerResult.output.toString());

    Example 2: Get the result and display the ouput

    // Launch "git" executable with "--version" parameter
    // Store the result (Buffer) in a variable
    var workerResult = SystemWorker.exec( 'git --version' );
    console.log(workerResult.output.toString());

    Example 3: Pass root folder options to the system worker

    var options = { folder: '/Users/yann/Desktop' };
    var workerResult = SystemWorker.exec( 'sh -c ls -la', options);
    console.log(workerResult.output.toString());

    Example 4: Pass parameters, quotes and env variables options to the system worker

    var myFolder = new Folder( 'PROJECT' );
    var options = {
        parameters : { folder_ref : myFolder },
        quote : '"',
        variables : { ENV_VAR_1 : 'value1' }
    };
    var workerResult = SystemWorker.exec( 'sh -c ls -la {file_ref}', options);
    console.log(workerResult.output.toString());

    Example 5: Run npm install in an emulated terminal

    var myFolder = new Folder( 'PROJECT' );
    var options = {
        parameters : { folder_ref : myFolder },
        quote : '"',
        emulateTerminal : true
    };
    var workerResult = SystemWorker.exec( 'cmd /c npm install', options);
    console.log(workerResult.output.toString());
    warning

    The system worker can only launch executable applications. All shell instructions must be preceded by a command line interpreter like bash, sh or cmd depending of the OS.

    Parameters

    Returns WAKSystemWorkerResult

    Returns the exit status, stdout and sterr

  • Calls to system worker and waits for its response (synchronous mode).

    Example 1: Do a simple CLI command

    // Launch "sh" executable with "-c" parameter and "ls -la /Users/<user>/Desktop" as the action to do
    var workerResult = SystemWorker.exec( ['sh', '-c', 'ls -la /Users/<user>/Desktop'] );
    console.log(workerResult.output.toString());

    Example 2: Get the result and display the ouput

    // Launch "git" executable with "--version" parameter
    // Store the result (Buffer) in a variable
    var workerResult = SystemWorker.exec( ['git', '--version'] );
    console.log(workerResult.output.toString());

    Example 3: Pass root folder options to the system worker

    var options = { folder: '/Users/yann/Desktop' };
    var workerResult = SystemWorker.exec( ['sh', '-c', 'ls -la'], options);
    console.log(workerResult.output.toString());

    Example 4: Pass parameters, quotes and env variables options to the system worker

    var myFolder = new Folder( 'PROJECT' );
    var options = {
        parameters : { folder_ref : myFolder },
        quote : '"',
        variables : { ENV_VAR_1 : 'value1' }
    };
    var workerResult = SystemWorker.exec( ['sh', '-c', 'ls -la {file_ref}'], options);
    console.log(workerResult.output.toString());

    Example 5: Run npm install in an emulated terminal

    var myFolder = new Folder( 'PROJECT' );
    var options = {
        parameters : { folder_ref : myFolder },
        quote : '"',
        emulateTerminal : true
    };
    var workerResult = SystemWorker.exec( ['cmd', '/c', 'npm install'], options);
    console.log(workerResult.output.toString());
    warning

    The system worker can only launch executable applications. All shell instructions must be preceded by a command line interpreter like bash, sh or cmd depending of the OS.

    Parameters

    • cli: String[]

      Command line to execute. First element is the executable. Then all next elements describe the parameters

    • Optional options: WAKSystemWorkerOptions

      Describes command line options

    Returns WAKSystemWorkerResult

    Returns the exit status, stdout and sterr