# Iterate over results of execute\_process

**URL:** <https://discourse.cmake.org/t/iterate-over-results-of-execute-process/6041>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [July 10, 2022, 3:08pm UTC](https://discourse.cmake.org/t/iterate-over-results-of-execute-process/6041 "2022-07-10T15:08:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anuj\_Choudhury](https://discourse.cmake.org/user_avatar/discourse.cmake.org/anuj_choudhury/32/2585_2.png) [@Anuj\_Choudhury](https://discourse.cmake.org/u/Anuj_Choudhury)\
**Post date:** [July 10, 2022, 3:08pm UTC](https://discourse.cmake.org/t/iterate-over-results-of-execute-process/6041/1 "2022-07-10T15:08:40Z")

</div>

How can i get the result of a bash command in a list variable ?  
Say I have the output of a command, run in cmake using `execute_process` (this output can be 100-200 lines large):

```auto
aa bb
cc dd 
ee ff

```

Now, I need to get this output into a cmake list variable, so that i can iterate over each line using `foreach`. So if i run:

```auto
foreach(line in ${final_line_list})
message(STATUS "${line}")
..other commands..
endforeach()

```

it should print:

```auto
aa bb
cc dd 
ee ff

```

I have tried to run sed and paste commands, but have been generally unsuccessful.

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [July 10, 2022, 3:25pm UTC](https://discourse.cmake.org/t/iterate-over-results-of-execute-process/6041/2 "2022-07-10T15:25:22Z")

</div>

What about:

```cmake
execute_process(COMMAND ... OUTPUT_VARIABLE outputs)
string(REPLACE "\n" ";" outputs "${outputs}")
foreach(line IN LISTS outputs)
  ...
endforeach()

```
