# cmake gives current working directory cannot establish error

**URL:** https://discourse.cmake.org/t/cmake-gives-current-working-directory-cannot-establish-error/2319
**Category:** Development
**Created:** [December 9, 2020, 9:42am UTC](https://discourse.cmake.org/t/cmake-gives-current-working-directory-cannot-establish-error/2319 "2020-12-09T09:42:38Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![jalpan](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/ea666f/32.png) [@jalpan](https://discourse.cmake.org/u/jalpan)
#### Post date: [December 9, 2020, 9:42am UTC](https://discourse.cmake.org/t/cmake-gives-current-working-directory-cannot-establish-error/2319/1 "2020-12-09T09:42:38Z")

</div>

while executing cmake command it gives me the following error  
“Current working directory cannot be established.”

I have executed cmake command from the shell script.  
rm -rf build && mkdir -p build && cd build &&   
cmake -DCMAKE\_TOOLCHAIN\_FILE=…/toolchain.cmake … 2\>\> output\_file.txt && make clean && make 2\>\> output\_file.txt && cd …

Let me know if you need more information.

Thanks,  
Jalpan Parekh

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [December 9, 2020, 4:13pm UTC](https://discourse.cmake.org/t/cmake-gives-current-working-directory-cannot-establish-error/2319/2 "2020-12-09T16:13:34Z")

</div>

Instead of doing all that it’s simpler to just use cmake like this:

rm -rf build  
cmake -S . -B build …

That way you can get rid of you mkdir/cd logic

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [December 9, 2020, 4:16pm UTC](https://discourse.cmake.org/t/cmake-gives-current-working-directory-cannot-establish-error/2319/3 "2020-12-09T16:16:20Z")

</div>

Also you don’t have to invoke make directly.

you can just cmake to build

cmake --build build --config Release

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [December 9, 2020, 4:17pm UTC](https://discourse.cmake.org/t/cmake-gives-current-working-directory-cannot-establish-error/2319/4 "2020-12-09T16:17:37Z")

</div>

cmake command ilne:  
[https://cmake.org/cmake/help/latest/manual/cmake.1.html](https://cmake.org/cmake/help/latest/manual/cmake.1.html)

---

<div class="post-metadata">

### Author: ![jalpan](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/ea666f/32.png) [@jalpan](https://discourse.cmake.org/u/jalpan)
#### Post date: [December 10, 2020, 9:00am UTC](https://discourse.cmake.org/t/cmake-gives-current-working-directory-cannot-establish-error/2319/5 "2020-12-10T09:00:43Z")

</div>

Hi John Palmer,

Thanks for the support.

Below command works fine:

`rm -rf build && cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake -S . -B build && cmake --build build --config Release`

Now how can I store error logs into one file? Can you please guide me?

Thanks,

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 10, 2020, 6:39pm UTC](https://discourse.cmake.org/t/cmake-gives-current-working-directory-cannot-establish-error/2319/6 "2020-12-10T18:39:39Z")

</div>

Error logs? Which error logs are you looking for?

---

<div class="post-metadata">

### Author: ![jalpan](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/ea666f/32.png) [@jalpan](https://discourse.cmake.org/u/jalpan)
#### Post date: [December 11, 2020, 5:08am UTC](https://discourse.cmake.org/t/cmake-gives-current-working-directory-cannot-establish-error/2319/7 "2020-12-11T05:08:45Z")

</div>

I am asking for capturing compile-time error logs in the file.  
For example, if I use the “make” command to compile my code then the `"make 2>> output_file.txt"` command will store error logs in the output\_file.txt file.

So how we can do the same with cmake --build command.

Thanks in advance.

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [December 11, 2020, 6:44am UTC](https://discourse.cmake.org/t/cmake-gives-current-working-directory-cannot-establish-error/2319/8 "2020-12-11T06:44:39Z")

</div>

`2>>` is not specific to `make`, you can use it with any command that outputs to stderr.  
Thus `cmake --build build --config Release 2>> output_file.txt` should be close to what you want.

I hope this helps.

---

<div class="post-metadata">

### Author: ![jalpan](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/ea666f/32.png) [@jalpan](https://discourse.cmake.org/u/jalpan)
#### Post date: [December 18, 2020, 10:55am UTC](https://discourse.cmake.org/t/cmake-gives-current-working-directory-cannot-establish-error/2319/9 "2020-12-18T10:55:58Z")

</div>

Thank you for the better understanding and it’s working now.
