Command line to execute
Describes command line options
Returns a system worker proxy
Calls a system worker (asynchronous mode). Use the system worker proxy to get the result.
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();
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);
var myFolder = new Folder( 'PROJECT' );
var options = {
parameters : { folder_ref : myFolder },
quote : '"',
emulateTerminal : true
};
var workerProxy = new SystemWorker( ['cmd', '/c', 'npm install'], options);
Command line to execute
Describes command line options
Returns a system worker proxy
Runs the given command and waits for its response (synchronous mode).
// 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());
// Launch "git" executable with "--version" parameter
// Store the result (Buffer) in a variable
var workerResult = SystemWorker.exec( 'git --version' );
console.log(workerResult.output.toString());
var options = { folder: '/Users/yann/Desktop' };
var workerResult = SystemWorker.exec( 'sh -c ls -la', options);
console.log(workerResult.output.toString());
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());
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());
Command line to execute
Describes command line options
Returns the exit status, stdout and sterr
Calls to system worker and waits for its response (synchronous mode).
// 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());
// Launch "git" executable with "--version" parameter
// Store the result (Buffer) in a variable
var workerResult = SystemWorker.exec( ['git', '--version'] );
console.log(workerResult.output.toString());
var options = { folder: '/Users/yann/Desktop' };
var workerResult = SystemWorker.exec( ['sh', '-c', 'ls -la'], options);
console.log(workerResult.output.toString());
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());
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());
Command line to execute. First element is the executable. Then all next elements describe the parameters
Describes command line options
Returns the exit status, stdout and sterr
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);
The system worker can only launch executable applications. All shell instructions must be preceded by a command line interpreter like
bash
,sh
orcmd
depending of the OS.