Advertisement
robertbira

Italian Translation Report: Node.js [Part 34 - 1131 words]

Sep 17th, 2018
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. Child Process
  2. Stability: 2 - Stable
  3. The module provides the ability to spawn child processes in a manner that is similar, but not identical, to popen(3).
  4. This capability is primarily provided by the function:
  5. By default, pipes for and are established between the parent Node.js process and the spawned child.
  6. These pipes have limited (and platform-specific) capacity.
  7. If the child process writes to in excess of that limit without the output being captured, the child process will block waiting for the pipe buffer to accept more data.
  8. This is identical to the behavior of pipes in the shell.
  9. Use the option if the output will not be consumed.
  10. The method spawns the child process asynchronously, without blocking the Node.js event loop.
  11. The function provides equivalent functionality in a synchronous manner that blocks the event loop until the spawned process either exits or is terminated.
  12. For convenience, the module provides a handful of synchronous and asynchronous alternatives to and
  13. Note that each of these alternatives are implemented on top of or
  14. spawns a shell and runs a command within that shell, passing the and to a callback function when complete.
  15. similar to except that it spawns the command directly without first spawning a shell by default
  16. spawns a new Node.js process and invokes a specified module with an IPC communication channel established that allows sending messages between parent and child.
  17. a synchronous version of that block the Node.js event loop.
  18. For certain use cases, such as automating shell scripts, the synchronous counterparts may be more convenient.
  19. In many cases, however, the synchronous methods can have significant impact on performance due to stalling the event loop while spawned processes complete.
  20. Asynchronous Process Creation
  21. The and methods all follow the idiomatic asynchronous programming pattern typical of other Node.js APIs.
  22. Each of the methods returns a instance. These objects implement the Node.js API, allowing the parent process to register listener functions that are called when certain events occur during the life cycle of the child process.
  23. The and methods additionally allow for an optional callback function to be specified that is invoked when the child process terminates.
  24. Spawning and files on Windows
  25. The importance of the distinction between and can vary based on platform.
  26. On Unix-type operating systems (Unix, Linux, macOS) can be more efficient because it does not spawn a shell by default.
  27. On Windows, however, and files are not executable on their own without a terminal, and therefore cannot be launched using
  28. When running on Windows, and files can be invoked using with the option set, with, or by spawning and passing the or file as an argument (which is what the option and do).
  29. In any case, if the script filename contains spaces it needs to be quoted.
  30. On Windows Only ...
  31. Script with spaces in the filename:
  32. The command to run, with space-separated arguments.
  33. Current working directory of the child process.
  34. Environment key-value pairs.
  35. Shell to execute the command with.
  36. See Shell Requirements and Default Windows Shell
  37. Largest amount of data in bytes allowed on or
  38. If exceeded, the child process is terminated.
  39. See caveat at
  40. Sets the user identity of the process
  41. Sets the group identity of the process
  42. Hide the subprocess console window that would normally be created on Windows systems.
  43. called with the output when process terminates.
  44. Spawns a shell then executes the within that shell, buffering any generated output.
  45. The string passed to the exec function is processed directly by the shell and special characters (vary based on) need to be dealt with accordingly:
  46. Double quotes are used so that the space in the path is not interpreted as multiple arguments
  47. Never pass unsanitized user input to this function.
  48. Any input containing shell metacharacters may be used to trigger arbitrary command execution.
  49. If a function is provided, it is called with the arguments
  50. On success, will be
  51. On error, will be an instance of
  52. The property will be the exit code of the child process while will be set to the signal that terminated the process.
  53. Any exit code other than is considered to be an error.
  54. The and arguments passed to the callback will contain the and output of the child process.
  55. By default, Node.js will decode the output as UTF-8 and pass strings to the callback.
  56. The option can be used to specify the character encoding used to decode the and output.
  57. If is, or an unrecognized character encoding, objects will be passed to the callback instead.
  58. If is greater than, the parent will send the signal identified by the property (the default is) if the child runs longer than milliseconds.
  59. Unlike the exec(3) POSIX system call, does not replace the existing process and uses a shell to execute the command.
  60. If this method is invoked as its ed version, it returns a for an with and properties.
  61. In case of an error (including any error resulting in an exit code other than 0), a rejected promise is returned, with the same object given in the callback, but with an additional two properties and
  62. The name or path of the executable file to run.
  63. List of string arguments.
  64. No quoting or escaping of arguments is done on Windows.
  65. Ignored on Unix.
  66. If, runs inside of a shell.
  67. Called with the output when process terminates.
  68. The function is similar to except that it does not spawn a shell by default.
  69. Rather, the specified executable is spawned directly as a new process making it slightly more efficient than
  70. The same options as are supported.
  71. Since a shell is not spawned, behaviors such as I/O redirection and file globbing are not supported.
  72. If the option is enabled, do not pass unsanitized user input to this function.
  73. The method is a special case of used specifically to spawn new Node.js processes.
  74. Like a object is returned.
  75. The returned will have an additional communication channel built-in that allows messages to be passed back and forth between the parent and child.
  76. See for details.
  77. It is important to keep in mind that spawned Node.js child processes are independent of the parent with exception of the IPC communication channel that is established between the two. Each process has its own memory, with their own V8 instances. Because of the additional resource allocations required, spawning a large number of child Node.js processes is not recommended.
  78. By default, will spawn new Node.js instances using the of the parent process.
  79. The property in the object allows for an alternative execution path to be used.
  80. Node.js processes launched with a custom will communicate with the parent process using the file descriptor (fd) identified using the environment variable on the child process.
  81. Unlike the fork(2) POSIX system call, does not clone the current process.
  82. The option available in is not supported by and will be ignored if set.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement