Closed
Description
Is your feature request related to a problem? Please describe.
It would be nice if child_process functionality, such as exec
, could accept a URL
(docs) for the cwd
argument. For example the File System writeFile
accepts a URL as its file
argument already. So it would be nice for the child_process module to do so as well for path arguments.
This is especially nice with ECMAScript modules since e.g. the old __dirname
does not exist anymore, but we are forced to use URL
to get a file path to the current file.
Describe the solution you'd like
// Using ESM Module syntax:
import { exec } from 'child_process/promises';
try {
const { stdout } = await exec(
'sysctl -n net.ipv4.ip_local_port_range',
{ encoding: 'utf8', cwd: new URL('../../', import.meta.url) } // without URL support we would have to have used .pathname here
);
console.log('successfully executed the child process command');
} catch (error) {
console.error('there was an error:', error.message);
}