* Spawns a new process synchronously using the given `file`. * @param {string} file * @param {string[]} [args] * @param {{ * cwd?: string | URL; * input?: string | Buffer | TypedArray | DataView; * argv0?: string; * stdio?: string | Array; * env?: Record ; * uid?:
(file, args, options)
| 865 | * }} |
| 866 | */ |
| 867 | function spawnSync(file, args, options) { |
| 868 | options = { |
| 869 | __proto__: null, |
| 870 | maxBuffer: MAX_BUFFER, |
| 871 | ...normalizeSpawnArguments(file, args, options), |
| 872 | }; |
| 873 | |
| 874 | debug('spawnSync', options); |
| 875 | |
| 876 | // Validate the timeout, if present. |
| 877 | validateTimeout(options.timeout); |
| 878 | |
| 879 | // Validate maxBuffer, if present. |
| 880 | validateMaxBuffer(options.maxBuffer); |
| 881 | |
| 882 | // Validate and translate the kill signal, if present. |
| 883 | options.killSignal = sanitizeKillSignal(options.killSignal); |
| 884 | |
| 885 | options.stdio = getValidStdio(options.stdio || 'pipe', true).stdio; |
| 886 | |
| 887 | if (options.input) { |
| 888 | const stdin = options.stdio[0] = { ...options.stdio[0] }; |
| 889 | stdin.input = options.input; |
| 890 | } |
| 891 | |
| 892 | // We may want to pass data in on any given fd, ensure it is a valid buffer |
| 893 | for (let i = 0; i < options.stdio.length; i++) { |
| 894 | const input = options.stdio[i]?.input; |
| 895 | if (input != null) { |
| 896 | const pipe = options.stdio[i] = { ...options.stdio[i] }; |
| 897 | if (isArrayBufferView(input)) { |
| 898 | pipe.input = input; |
| 899 | } else if (typeof input === 'string') { |
| 900 | pipe.input = Buffer.from(input, options.encoding); |
| 901 | } else { |
| 902 | throw new ERR_INVALID_ARG_TYPE(`options.stdio[${i}]`, |
| 903 | ['Buffer', |
| 904 | 'TypedArray', |
| 905 | 'DataView', |
| 906 | 'string'], |
| 907 | input); |
| 908 | } |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | return child_process.spawnSync(options); |
| 913 | } |
| 914 | |
| 915 | |
| 916 | function checkExecSyncError(ret, args, cmd) { |
searching dependent graphs…