tags:

views:

121

answers:

2

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?

+4  A: 

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().

Warren Young
Sorry could you explain what you mean by "You want cd() instead"
Damian
I mean that, within the erl shell, you can say this: cd("d:/temp"). (Note the forward slashes. Avoids the need to double your backslashes, as required in Erlang strings.)
Warren Young
+5  A: 

Try using file:set_cwd(Dir) to change your current dir.

Prikrutil
Thanks, I missed that when searching for the alternative to the cd() shell command. I've edited my post above to include it. +1
Warren Young
I just tried that seconds before you posted and it works. Excellent. I was about to give up and go to bed. Now I can go to bed happy.
Damian