# execute\_process ignoring options

**URL:** <https://discourse.cmake.org/t/execute-process-ignoring-options/2918>\
**Category:** Code\
**Created:** [March 8, 2021, 3:57pm UTC](https://discourse.cmake.org/t/execute-process-ignoring-options/2918 "2021-03-08T15:57:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![modelmanjohn](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/f05b48/32.png) [@modelmanjohn](https://discourse.cmake.org/u/modelmanjohn)\
**Post date:** [March 8, 2021, 3:57pm UTC](https://discourse.cmake.org/t/execute-process-ignoring-options/2918/1 "2021-03-08T15:57:36Z")

</div>

Hello, I’m trying to get an execute\_process command working, and so far, it seems like its ignoring options of the command itself.  
The command I’m trying to run is:  
python3 -B file.py  
The -B option is the problem: it specifies for python to NOT write.pyc files on import, typically into a **pycache** directory. But it continues to do so.

Some examples that I’ve tried:  
execute\_process(COMMAND python3 -B file.py)  
execute\_process(COMMAND “python3 -B file.py”)  
execute\_process(COMMAND “python3” “-B” “file.py”)  
set(PYCMD “python3 -B file.py”)  
execute\_process(COMMAND ${PYCMD})  
execute\_process(COMMAND “${PYCMD}”)  
set(PYCMD python3 -B file.py)  
execute\_process(COMMAND ${PYCMD})  
execute\_process(COMMAND “${PYCMD}”)  
set(PYCMD “python3” “-B” “file.py”)  
execute\_process(COMMAND ${PYCMD})  
execute\_process(COMMAND “${PYCMD}”)

I’ve also tried variations with the -B to see if an escape char was needed to no avail.

I’ve set RESULT\_VARIABLE, OUTPUT\_VARIABLE, and ERROR\_VARIABLE on these, and I never seen an error, the result is always 0 (success), and the output prints out a string that says the command worked (ie file.py prints out a string on success of doing its work)

I’ve also tried setting the environmental variable PYTHONDONTWRITEBYTECODE=1 which should cause the python3 to not write the bytecode either, but it still does.

thank you, any help would be appreciated.

---

<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:** [March 8, 2021, 3:58pm UTC](https://discourse.cmake.org/t/execute-process-ignoring-options/2918/2 "2021-03-08T15:58:49Z")

</div>

What happens if you run it outside of CMake? Does it exhibit the behavior you expect there?

---

<div class="post-metadata">

**Author:** ![modelmanjohn](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/f05b48/32.png) [@modelmanjohn](https://discourse.cmake.org/u/modelmanjohn)\
**Post date:** [March 8, 2021, 4:11pm UTC](https://discourse.cmake.org/t/execute-process-ignoring-options/2918/3 "2021-03-08T16:11:21Z")

</div>

When I run the command manually, it operates as expected - no .pyc files created, no **pycache** directory created.

---

<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:** [March 8, 2021, 4:17pm UTC](https://discourse.cmake.org/t/execute-process-ignoring-options/2918/4 "2021-03-08T16:17:51Z")

</div>

Hmm. CMake doesn’t really interfere at all here. Some investigation into what is happening here would be needed on your machine. Here’s my test:

```auto
==> foo.py <==
print('bar')

==> bar.py <==
import foo

==> foo.cmake <==
execute_process(COMMAND python3 -B bar.py)
if (EXISTS "${CMAKE_CURRENT_FILE_DIR}/ __pycache__")
  message(FATAL_ERROR "boo")
endif ()

```

This works on my machine at least.
