0

Let's say I do node someCommand.js. I want this command to change the directory of the terminal.

When I tried process.chdir(newDir), that just changes the directory in the context of the script - once the command exits, the terminal is still in the old directory.

Kousha
  • 32,871
  • 51
  • 172
  • 296
  • What do you want to do? `process.chdir(newDir)` did the work for you no? – Hassaan Ali Jan 16 '22 at 08:10
  • https://stackoverflow.com/questions/55577799/send-command-to-running-node-js-process – SoftViruS Jan 16 '22 at 08:25
  • Ironically, the `node` executable has options to specify the diagnostic directory, the heap profiler directory, the report directory but not the current directory, so probably they expect you to just run `cd /somedir` before running node. – GOTO 0 Jan 16 '22 at 09:01
  • [You can't, and you shouldn't](https://stackoverflow.com/q/2375003/1048572). – Bergi Jan 16 '22 at 10:07
  • @GOTO0 the current working directory is not an environment variable. Doing `cd` in a shell is the way to go. See also [Specifying working directory when starting process on Windows](https://superuser.com/q/396394/175275) and [How does Unix keep track of the working directory](https://unix.stackexchange.com/q/413204/190272) – Bergi Jan 16 '22 at 10:14
  • @Bergi thank you. That's a shame that it cannot be done :( – Kousha Jan 16 '22 at 19:48
  • I'm not even sure *why* you would want to do that though – Bergi Jan 16 '22 at 20:16

0 Answers0