# Capturing shell output

**URL:** <https://swi-prolog.discourse.group/t/capturing-shell-output/7301>\
**Category:** General\
**Created:** [March 11, 2024, 4:07pm UTC](https://swi-prolog.discourse.group/t/capturing-shell-output/7301 "2024-03-11T16:07:32Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![brebs](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@brebs](https://swi-prolog.discourse.group/u/brebs)\
**Post date:** [March 11, 2024, 6:27pm UTC](https://swi-prolog.discourse.group/t/capturing-shell-output/7301/3 "2024-03-11T18:27:20Z")

</div>

> [@esad](#):
>
> it’s as easy as just quoting the command in backticks

What about:

- Exit code - only provided at the end. Normally 0 for success, but [grep returns 1](https://stackoverflow.com/questions/49730043/the-exit-status-code-for-the-grep-command) if no match, which might or might not be acceptable also.
- Do you want to stream the output (e.g. piping through `gzip`), or wait for the definiteness of the exit code first?
- STDERR output, if any (rather than just STDOUT)
- For completeness - might want to be piping via STDIN to e.g. `gzip`

I gave some basic predicates at [How to get shell echo in Prolog variables - #15 by brebs](https://swi-prolog.discourse.group/t/how-to-get-shell-echo-in-prolog-variables/6547/15)

Haven’t looked at it since. This could do with a standard library, sure.

---

_[View the full topic](https://swi-prolog.discourse.group/t/capturing-shell-output/7301)._
