Ceci est une ancienne révision du document !
Table des matières
Process [En cours de Traduction Wismerheal][WSL]
Cet objet vous permet de lancer et manager un processus. (programme)
Fonctions
Process
Fonction de construction.
Syntaxe
var myObject = new Process();
var myObject = new Process(parameters);
Arguments
- parameters - (object) les paramètres
- workingDirectory - (string) le dossier de travail
- processChannelMode - (ProcessChannelMode) le mode du "channel" du processus
- readChannel - (ProcessChannel) le "channel" du processus à lire
- onError - (onError) appelé quand une erreur survient
- onFinished - (onFinished) appelé quand le processus est terminé
- onReadyReadStandardError - (onReadyReadStandardError) appelé quand le processus dispose de données sur le "channel" d'erreur standard
- onReadyReadStandardOutput - (onReadyReadStandardOutput) appelé quand le processus dispose de données sur le "channel" standard de sortie
- onStarted - (onStarted) appellé quand le processus a commencé
- onStateChanged - (onStateChanged) appelé quand l'état du processus a changé
Example
var myObject = new Process();
var myObject = new Process({ workingDirectory: "/home/user", onStarted: function() { Console.print("Started!"); }, onFinished: function() { Console.print("Finished!"); } });
list
Renvoie un tableau de ProcessHandle lié à tous les processus en cours d’exécution.
Syntaxe
Process.list();
Renvoie
- (array) un tableau de ProcessHandle lié à tous les processus en cours d’exécution
thisProcess
Renvoi un ProcessHandle lié au processus d'Actionaz.
Syntaxe
Process.thisProcess();
Renvoie
- (array) un ProcessHandle lié au processus d'Actionaz
startDetached
Lance le processus en mode détaché et renvoie un ProcessHandle qui lui est lié. Vous aurez moins de contrôle sur le processus qu'en mode attaché, cependant il sera indépendant de l'actuelle exécution.
Syntaxe
Process.startDetached(filename);
Process.startDetached(filename, parameters);
Process.startDetached(filename, parameters, workingDirectory);
Arguments
- filename - (string) le nom de fichier/commande du processus à lancer
- parameters - (array) un tableau de paramètres
- workingDirectory - (string) le dossier de travail
Renvoie
- (array) un ProcessHandle lié au processus lancé
Exceptions
- (FilenameError) nom de fichier non valide
- (StartProcessError) ne parvient pas à lancer le processus
Méthodes
handle
Renvoie un ProcessHandle lié au processus lancé.
Syntaxe
myObject.handle();
Renvoie
- (ProcessHandle) un ProcessHandle lié au processus lancé
id
Renvoie l'identifiant (id) du processus lancé.
Syntaxe
myObject.id();
REnvoie
- (integer) l'identifiant (id) du processus lancé
start
Lance le processus.
Syntaxe
myObject.start(filename);
myObject.start(filename, parameters);
myObject.start(filename, parameters, openMode);
Arguments
- filename - (string) le nom de fichier/commande du processus à lancer
- parameters - (array) un tableau de paramètres
- openMode - (OpenMode) le mode d'ouverture à utiliser (défaut: lecture & écriture)
Renvoie
- (Process) ce Processus
Exceptions
- (FilenameError) nom de fichier non valide
state
Renvoie l'état du processus lancé.
Syntaxe
myObject.state();
Renvoie
- (ProcessState) l'état du processus lancé
error
Renvoie l'état de l'erreur du processus lancé.
Syntaxe
myObject.error();
Renvoie
- (ProcessError) l'état de l'erreur du processus lancé
exitCode
Renvoie le code de sortie du processus.
Syntaxe
myObject.exitCode();
Renvoie
- (integer) le code de sortie du processus
exitStatus
Renvoie le statut du processus de sortie.
Syntaxe
myObject.exitStatus();
Renvoie
- (ExitStatus) le statut du processus de sortie
readError
Renvoie le contenu de l’erreur de sortie standard en un RawData .
Syntaxe
myObject.readError();
Renvoie
read
Renvoie le contenu de la sortie standard en un RawData .
Syntaxe
myObject.read();
Renvoie
readErrorText
Renvoie le contenu d'erreur de sotie standard sous forme de texte.
Syntaxe
myObject.readErrorText();
myObject.readErrorText(encoding);
Arguments
- encoding - (Encoding) l'encodage à utiliser
Renvoie
- (string) le contenu d'erreur de sotie standard sous forme de texte
readText
Renvoie le contenu standard de sortie sous forme de texte.
Syntaxe
myObject.readText();
myObject.readText(encoding);
Arguments
- encoding - (Encoding) l'encodage à utiliser
Renvoie
- (string) le contenu de sortie standard sous forme de texte
atEnd
Renvoie vrai si le processus n'est pas en cours d'exécution et si aucune donnée ne peut être lue.
Syntaxe
myObject.atEnd();
Returns
- (boolean) vrai si le processus n'est pas en cours d'exécution et si aucune donnée ne peut être lue
bytesAvailable
Renvoi le nombre de bytes qui peuvent être lus.
Syntaxe
myObject.bytesAvailable();
Renvoie
- (integer) le nombre de bytes qui peuvent être lus
bytesToWrite
Renvoie le nombre de bytes qui doivent toujours être écrit.
Syntaxe
myObject.bytesToWrite();
Renvoie
- (integer) le nombre de bytes qui doivent toujours être écrit
canReadLine
Renvoie vrai si une ligne peut être lue.
Syntaxe
myObject.canReadLine();
Renvoie
- (boolean) vrai si une ligne peut être lue
write
Écrit des données sur le processus.
Syntaxe
myObject.write(data);
Arguments
- data - (mixed) les données à écrire
Renvoie
- (Process) ce Processus
writeText
Écrit du texte sur le processus.
Syntaxe
myObject.writeText(text, encoding);
Arguments
- text - (string) the text to write
- encoding - (Encoding) the encoding to use
Returns
- (Process) this Process
setWorkingDirectory
Sets the working directory. This only works when the process is not already started.
Syntax
myObject.setWorkingDirectory(workingDirectory);
Arguments
- workingDirectory - (string) the text to write
Returns
- (Process) this Process
setProcessChannelMode
Sets process's channel mode. This only works when the process is not already started.
Syntax
myObject.setProcessChannelMode(channelMode);
Arguments
- channelMode - (ProcessChannelMode) the process's channel mode
Returns
- (Process) this Process
setEnvironment
Sets the process's environment variables. This only works when the process is not already started.
Syntax
myObject.setEnvironment(environment);
Arguments
- environment - (object) the process's environment variable
Returns
- (Process) this Process
Example
myObject.setEnvironment({ PATH: "c:\\;c:\\path", MYVAR: "hello" });
updateEnvironment
Updates the process's environment variables. This only works when the process is not already started.
Syntax
myObject.updateEnvironment(environment);
Arguments
- environment - (object) the process's environment variable
Returns
- (Process) this Process
Example
myObject.updateEnvironment({ PATH: "c:\\;c:\\path", MYVAR: "hello" });
setReadChannel
Sets process's read channel.
Syntax
myObject.setReadChannel(channel);
Arguments
- channel - (ProcessChannel) the process's read channel
Returns
- (Process) this Process
setStandardErrorFile
Sets the standard error file.
Syntax
myObject.setStandardErrorFile(fileName);
myObject.setStandardErrorFile(fileName, openMode);
Arguments
- fileName - (string) the filename
- channel - (OpenMode) the file's open mode (default: Truncate)
Returns
- (Process) this Process
setStandardInputFile
Sets the standard input file.
Syntax
myObject.setStandardInputFile(fileName);
Arguments
- fileName - (string) the filename
Returns
- (Process) this Process
setStandardOutputFile
Sets the standard output file.
Syntax
myObject.setStandardOutputFile(fileName);
myObject.setStandardOutputFile(fileName, openMode);
Arguments
- fileName - (string) the filename
- channel - (OpenMode) the file's open mode (default: Truncate)
Returns
- (Process) this Process
setStandardOutputProcess
Sets the standard output process.
Syntax
myObject.setStandardOutputFile(process);
Arguments
- process - (Process) the output process
Returns
- (Process) this Process
Exceptions
- (InvalidProcessError) invalid process
waitForFinished
Freezes the execution until the process has finished.
Syntax
myObject.waitForFinished(waitTime);
myObject.waitForFinished();
Arguments
- waitTime - (integer) the time to wait (milliseconds, default: 30000)
Returns
- (Process) this Process
Exceptions
- (WaitForFinishedError) wait for finished failed
waitForStarted
Freezes the execution until the process has started.
Syntax
myObject.waitForStarted(waitTime);
myObject.waitForStarted();
Arguments
- waitTime - (integer) the time to wait (milliseconds, default: 30000)
Returns
- (Process) this Process
Exceptions
- (WaitForStartedError) wait for started failed
waitForBytesWritten
Freezes the execution until the data has been written.
Syntax
myObject.waitForBytesWritten(waitTime);
myObject.waitForBytesWritten();
Arguments
- waitTime - (integer) the time to wait (milliseconds, default: 30000)
Returns
- (Process) this Process
Exceptions
- (WaitForBytesWrittenError) wait for bytes written failed
waitForReadyRead
Freezes the execution until data is available.
Syntax
myObject.waitForReadyRead(waitTime);
myObject.waitForReadyRead();
Arguments
- waitTime - (integer) the time to wait (milliseconds, default: 30000)
Returns
- (Process) this Process
Exceptions
- (WaitForReadyReadError) wait for ready read failed
close
Tries to close the process gracefully.
Syntax
myObject.close();
Returns
- (Process) this Process
kill
Kills the process.
Syntax
myObject.kill();
Returns
- (Process) this Process
terminate
Terminates the process.
Syntax
myObject.terminate();
Returns
- (Process) this Process
Events
onError
Called when an error occured.
Syntax
myObject.onError = function(processError) {};
Arguments
- processError - (ProcessError) the process error that has occured
Example
myObject.onError = function(processError) { //Event action };
onFinished
Called when the process has finished.
Syntax
myObject.onFinished = function(exitCode, exitStatus) {};
Arguments
- exitCode - (integer) the process's exit code
- exitStatus - (ExitStatus) the process's exit status
Example
myObject.onFinished = function(exitCode, exitStatus) { //Event action };
onReadyReadStandardError
Called when there is data available on the standard error output.
Syntax
myObject.onReadyReadStandardError = function() {};
Example
myObject.onReadyReadStandardError = function() { //Event action };
onReadyReadStandardOutput
Called when there is data available on the standard output.
Syntax
myObject.onReadyReadStandardOutput = function() {};
Example
myObject.onReadyReadStandardOutput = function() { //Event action };
onStarted
Called when the process has started executing.
Syntax
myObject.onStarted = function() {};
Example
myObject.onStarted = function() { //Event action };
onStateChanged
Called when the process's state has changed.
Syntax
myObject.onStateChanged = function(newState) {};
Arguments
- newState - (ProcessState) the process's state
Example
myObject.onStateChanged = function(newState) { //Event action };
Enumerations
ProcessError
A process error.
Values
- FailedToStart: the file cannot be found or insufficient permissions
- Crashed: the process has crashed after having started successfully
- Timedout: the last waitFor… method failed
- WriteError: the process is not running or it may have closed it's input channel
- ReadError: the process is not running
- UnknownError: an unknown error has occured
ExitStatus
The process's exit status.
Values
- NormalExit: the process finished normally
- CrashExit: the process crashed
ProcessState
The process's status.
Values
- NotRunning: the process is not running
- Starting: the process is starting
- Running: the process is running
ProcessChannel
A process's channel.
Values
- StandardOutput: the standard output channel
- StandardError: the standard error output channel
ProcessChannelMode
A process's channel mode.
Values
- SeparateChannels: the standard error and output channels are separated
- MergedChannels: the standard error channel is redirected to the the standard output channel
- ForwardedChannels: the output of both channels is redirected to the parent process
OpenMode
A process's channel open mode.
Values
- ReadOnly: process channel opened for reading only
- WriteOnly: process channel opened for writing only
- ReadWrite: process channel opened for reading and writing
- Truncate: process channel opened for writing, erases any previous content
- Text: process channel opened in text mode
- Unbuffered: process channel opened in unbuffered mode