Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let child_process 'cwd' arguments accept a URL #38861

Closed
thernstig opened this issue May 31, 2021 · 2 comments
Closed

Let child_process 'cwd' arguments accept a URL #38861

thernstig opened this issue May 31, 2021 · 2 comments
Labels
child_process Issues and PRs related to the child_process subsystem. feature request Issues that request new features to be added to Node.js.

Comments

@thernstig
Copy link
Contributor

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);
}
@Ayase-252 Ayase-252 added child_process Issues and PRs related to the child_process subsystem. feature request Issues that request new features to be added to Node.js. labels May 31, 2021
XadillaX added a commit to XadillaX/node that referenced this issue May 31, 2021
@Trott
Copy link
Member

Trott commented May 31, 2021

@nodejs/child_process

@bl-ue
Copy link
Contributor

bl-ue commented Jun 2, 2021

What if URL were an internet address like this?

const myURL = new URL('/foo', 'https://example.org/');
// https://example.org/foo

Edit: see https://github.com/nodejs/node/pull/38862/files#diff-78a58a7046b99f3e5572d1d8a378139226f9963a5d6d7b51551c29f431285c89R72-R76

targos pushed a commit that referenced this issue Jun 11, 2021
PR-URL: #38862
Fixes: #38861
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
targos pushed a commit that referenced this issue Sep 4, 2021
PR-URL: #38862
Fixes: #38861
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants