# profraw file generation is corrupted if command strings are given automatic

**URL:** <https://discourse.cmake.org/t/profraw-file-generation-is-corrupted-if-command-strings-are-given-automatic/11714>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [September 17, 2024, 11:56pm UTC](https://discourse.cmake.org/t/profraw-file-generation-is-corrupted-if-command-strings-are-given-automatic/11714 "2024-09-17T23:56:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Selviniah](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/3ec8ea/32.png) [@Selviniah](https://discourse.cmake.org/u/Selviniah)\
**Post date:** [September 17, 2024, 11:56pm UTC](https://discourse.cmake.org/t/profraw-file-generation-is-corrupted-if-command-strings-are-given-automatic/11714/1 "2024-09-17T23:56:24Z")

</div>

I generating `profaw` file with compiler option. If I run the executable, the executable will generate every time `profraw` file. I wanted to automate this process

This way it perfectly works for executing twice the executable automatically.

```cmake
add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD 
                COMMAND ${CMAKE_COMMAND} -E echo " 2. Execution of: ${EXECUTABLE_NAME}"
                COMMAND $<TARGET_FILE:${EXECUTABLE_NAME}>
                COMMAND ${CMAKE_COMMAND} -E sleep 1
                
                COMMAND ${CMAKE_COMMAND} -E echo " 2. Execution of: ${EXECUTABLE_NAME}"
                COMMAND $<TARGET_FILE:${EXECUTABLE_NAME}>
                COMMAND ${CMAKE_COMMAND} -E sleep 1)

```

However I wanted to do run arbitrary number of times the executable so I wrote this command. However there’s 2 problems

1. The command executing always twice as much the given number. For example I set **SET\_PROFRAW\_COUNT** to 5 so it will execute 10 times
2. Generated profraw files are highly corrupted and non-functional

```cmake
set(SET_PROFRAW_COUNT 5)

    #Geneate the string for number of times executing the command 
    math(EXPR SET_PROFRAW_COUNT "${SET_PROFRAW_COUNT} -1") ##This is required because foreach executing 0-5 5th inclusive
    set(COMMAND_LIST "")
    foreach (i RANGE ${SET_PROFRAW_COUNT})
        LIST(APPEND COMMAND_LIST
                COMMAND ${CMAKE_COMMAND} -E echo " ${i}. Execution of: ${EXECUTABLE_NAME}"
                COMMAND $<TARGET_FILE:${EXECUTABLE_NAME}>
                COMMAND ${CMAKE_COMMAND} -E sleep 1)
    endforeach ()

    add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD ${COMMAND_LIST}

```
