I am trying to change the directory in the command line from a gen_server using
os:cmd("cd d:\temp").
but nothing happense, the return is just an empty list and I remain in the same directory. any ideas?
Try using file:set_cwd(Dir) to change your current dir.
cmd() runs a sub-shell, which you're telling to change directory, then the sub-shell exits, having changed nothing about its parent process's environment.
You want to use cd() instead, if you're in the shell, or file:set_cwd() at runtime within an Erlang program.
Another option, if you want to run another program and have its working directory be different from the one Erlang is using is to pass the {cd, Dir} tuple to open_port().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With