Terminal cd command not working from Scala script

From Wikipedia on cd command:

[...] on Unix systems cd calls the chdir() POSIX C function. This means that when the command is executed, no new process is created to migrate to the other directory as is the case with other commands such as ls. Instead, the shell itself executes this command.

There is even a quote about Java there:

[...] neither the Java programming language nor the Java Virtual Machine supports chdir() directly; a change request remained open for over a decade while the team responsible for Java considered the alternatives, though by 2008 the request was denied after only limited support was introduced [...]

Try it yourself:

$ which ls
/bin/ls
$ which cd
$

In simple words, cd is not a program (process) you can run (like /bin/ls) - it is more of a command line directive.

What do you want to achieve? Changing the current working directory in Java? or change the working directory of the process you just created?

Tags:

Io

Shell

Scala