Problems with chdir

Hello fellows,

I’m new using FreeFeem, but I think the thing I’m trying to do is so simple.
The code is

exec("mkdir result");
exec("chdir result");
	ofstream teste("teste.txt");
	teste << "hello World!";
exec("cd ..");

For some reason, it is not working. My expectation of this code is

  1. Create the folder result
  2. Enter the folder result
  3. create teste.txt and write “hello World!” in it.
  4. Get back to the initial directory.

But, it create the “teste.txt” file inside original folder. I can’t understand why.
There is no compiling error. I don’t know.

I used “cd” instead of “chdir”, but no success either.

Please help. I guess is something very dumb, but I can’t figure what it is.
Thanks.

1 Like

Each exec will spawn a new and independent process, so it’s wrong to expect that after exec("chdir result");, any other exec calls will have a working directory set to result.

thank you for the answer.

Do you know how can I fix the code, in order to work properly?

thanks again

exec("mkdir result ");
	ofstream teste("result/teste.txt");
	teste << "hello World!";
1 Like

THANK YOU SO MUCH!
I tried so many formats but never this one.