You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cabal run should send info logging to stderr not stdout #7790
cabal run prints stuff like "up to date" to stdout. So running an executable and cabal run an executable give different output to stdout, which is no good when the executable is producing output for e.g. machine consumption. We should do our info logging to stderr.
Reacted by Rihards Krišlauks, matil019, Ken Micklas, George Thomas, pacien, Fumiaki Kinoshita, Francesco Gazzetta, jwaldmann and MangoIV
Not sure about that, maybe there are programs expecting the actual behaviour, i.e. both cabal and the progam output in stdout.
What about separate both outputs in a standard way (using -?), including a comment
Note that Cabal already prints some of its warnings on stderr.
This is also the case for GHC warnings.
As a result, we get logs split between both stderr and stdout,
before the output of the target executable that is being run.
The output is someting like this (prefixes and blank lines added):
> cabal run print-csv
STDERR: Warning: The package list for 'hackage.haskell.org' does not exist.
STDERR: Run 'cabal update' to download it.
STDOUT: Resolving dependencies...
STDOUT: Build profile: -w ghc-9.0.2 -O1
STDOUT: [...]
STDERR:
STDERR: lib/[...[:19:1: warning: [-Worphans]
STDERR: Orphan instance: instance CSV.ToField URI
STDERR: |
STDERR:23 | instance CSV.ToField URI where
STDERR: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
STDOUT: Linking [...] ...
STDOUT: [CSV/JSON/stuff I would actually like to capture or redirect]
jneira:
Not sure about that, maybe there are programs expecting the actual behaviour,
i.e. both cabal and the progam output in stdout.
Given that there is no way of separating the output of Cabal, GHC and the
target executable, currently happening on both stderr and stdout, I doubt that
anyone is making use of the current behaviour.
I'm having to work around this right now -- I'm packaging a version of pandoc for Arch Linux, and am considering moving it back to using cabal for its build system. However, whereas stack run -- --bash-completion > pandoc.bash only captures the pandoc-cli --bash-completion output, cabal run pandoc-cli -- --bash-completion > pandoc.bash also captures cabal's output.
(I only caught this because my packaging system was warning the generated script contained references to the source directory that it shouldn't have)
EDIT: For future readers -- a workaround mentioned in #5595 is to pass -v0 (note! no space, it is parsed differently) to cabal run. I'm currently trying it out, I will edit this if it turns out to work. It works, but I'm having trouble getting cabal to emit a useful log somewhere to be able to track progress (since -v0 silences cabal completely)
Note: #4652 raised my hopes that -vnormal+stderr would allow splitting the streams, but it's still emitting the [n of N] Compiling M.N.O messages on stdout. At least some of the info output is sent to stderr instead. EDIT: reading the comments there again, I see those messages are by GHC, so I don't see a way of avoiding these messages. Hopefully, cabal build && cabal run -vnormal+stderr will avoid the ghc output, but otherwise -v0 seems to be the most robust solution.
That didn't work for me, but then the project I was working with (pandoc) has multiple components, so cabal build; cabal run didn't take care of all the compilation I needed.
Activity
fgaz commentedon Nov 2, 2021
Related/duplicates: #5595 #4652 #4789
jneira commentedon Nov 2, 2021
Not sure about that, maybe there are programs expecting the actual behaviour, i.e. both cabal and the progam output in stdout.
What about separate both outputs in a standard way (using
-?), including a commentSee comment in #4789: #4789
andreasabel commentedon Dec 30, 2022
@jneira, something went wrong; this does not link to a comment, only to the PR.
jneira commentedon Dec 30, 2022
tbh i cant determine what is the relevant comment right now 😅
pacien commentedon May 9, 2023
Note that Cabal already prints some of its warnings on stderr.
This is also the case for GHC warnings.
As a result, we get logs split between both stderr and stdout,
before the output of the target executable that is being run.
The output is someting like this (prefixes and blank lines added):
jneira:
Given that there is no way of separating the output of Cabal, GHC and the
target executable, currently happening on both stderr and stdout, I doubt that
anyone is making use of the current behaviour.
hseg commentedon Mar 19, 2025
I'm having to work around this right now -- I'm packaging a version of
pandocfor Arch Linux, and am considering moving it back to using cabal for its build system. However, whereasstack run -- --bash-completion > pandoc.bashonly captures thepandoc-cli --bash-completionoutput,cabal run pandoc-cli -- --bash-completion > pandoc.bashalso captures cabal's output.(I only caught this because my packaging system was warning the generated script contained references to the source directory that it shouldn't have)
EDIT: For future readers -- a workaround mentioned in #5595 is to pass
-v0(note! no space, it is parsed differently) tocabal run.I'm currently trying it out, I will edit this if it turns out to work.It works, but I'm having trouble getting cabal to emit a useful log somewhere to be able to track progress (since-v0silences cabal completely)Note: #4652 raised my hopes that
-vnormal+stderrwould allow splitting the streams, but it's still emitting the[n of N] Compiling M.N.Omessages on stdout. At least some of the info output is sent to stderr instead. EDIT: reading the comments there again, I see those messages are by GHC, so I don't see a way of avoiding these messages. Hopefully,cabal build && cabal run -vnormal+stderrwill avoid theghcoutput, but otherwise-v0seems to be the most robust solution.fgaz commentedon Mar 20, 2025
Another workaround is first building the executable, then running the output of
cabal list-binhseg commentedon Mar 20, 2025
That didn't work for me, but then the project I was working with (pandoc) has multiple components, so
cabal build; cabal rundidn't take care of all the compilation I needed.andreasabel commentedon May 25, 2026
I found that
cabal runstill printsResolving dependencies...tostdout.Would be great if this issue could be fixed.
Fix cabal run logging stream for issue haskell#7790