Skip to content

cabal run should send info logging to stderr not stdout #7790

Open

Description

@gbaz

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.

Activity

  1. fgaz commented on Nov 2, 2021

    @fgaz
    Member

    Related/duplicates: #5595 #4652 #4789

  2. jneira commented on Nov 2, 2021

    @jneira
    Member

    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

    See comment in #4789: #4789

  3. andreasabel commented on Dec 30, 2022

    @andreasabel
    Member

    See comment in #4789: #4789

    @jneira, something went wrong; this does not link to a comment, only to the PR.

  4. jneira commented on Dec 30, 2022

    @jneira
    Member

    tbh i cant determine what is the relevant comment right now 😅

  5. pacien commented on May 9, 2023

    @pacien

    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.

  6. hseg commented on Mar 19, 2025

    @hseg

    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.

  7. fgaz commented on Mar 20, 2025

    @fgaz
    Member

    Another workaround is first building the executable, then running the output of cabal list-bin

  8. hseg commented on Mar 20, 2025

    @hseg

    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.

  9. added
    re: error-message
    on Apr 10, 2025
  10. andreasabel commented on May 25, 2026

    @andreasabel
    Member

    I found that cabal run still prints Resolving dependencies... to stdout.
    Would be great if this issue could be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    attention: pr-welcomecabal-install: cmd/runre: error-messagetype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions