execute_process ignoring options

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.

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

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

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:

==> 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.