MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / exec

Function exec

javascript/selenium-webdriver/io/exec.js:123–160  ·  view source on GitHub ↗

* Spawns a child process. The returned Command may be used to wait * for the process result or to send signals to the process. * * @param {string} command The executable to spawn. * @param {Options=} opt_options The command options. * @return {!Command} The launched command.

(command, opt_options)

Source from the content-addressed store, hash-verified

121 * @return {!Command} The launched command.
122 */
123function exec(command, opt_options) {
124 const options = opt_options || {}
125
126 let proc = childProcess.spawn(command, options.args || [], {
127 env: options.env || process.env,
128 stdio: options.stdio || 'ignore',
129 })
130
131 // This process should not wait on the spawned child, however, we do
132 // want to ensure the child is killed when this process exits.
133 proc.unref()
134 process.once('exit', onProcessExit)
135
136 const result = new Promise((resolve, reject) => {
137 proc.once('exit', (code, signal) => {
138 proc = null
139 process.removeListener('exit', onProcessExit)
140 resolve(new Result(code, signal))
141 })
142
143 proc.once('error', (err) => {
144 reject(err)
145 })
146 })
147 return new Command(result, killCommand)
148
149 function onProcessExit() {
150 killCommand('SIGTERM')
151 }
152
153 function killCommand(signal) {
154 process.removeListener('exit', onProcessExit)
155 if (proc) {
156 proc.kill(signal)
157 proc = null
158 }
159 }
160}
161
162// Exported to improve generated API documentation.
163

Callers 1

startMethod · 0.85

Calls 3

resolveFunction · 0.50
rejectFunction · 0.50
removeListenerMethod · 0.45

Tested by

no test coverage detected