Skip to content

How can I redirect or silence stderr in Process(...)? #5497

Answered by fingolfin
kiryph asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately Process does not currently allow redirecting stderr (see also issue #4657).

You can however use a trick and instead of directly executing the target program, execute another program (such as a shell) which performs the redirection. This is indeed what some code does by using Exec, e.g. this:

Exec(Concatenation("firefox \"file://", url,"\" >/dev/null 2>&1 &"));

However, Exec is otherwise a bad tool, as it does not allow check exit codes (to see if the command actually worked) and if you want to hide or capture output, it must always go through temporary files). So in general I recommend not using it. Relatedly, PR #5103 adds an alternative "better" version of Exec.

Luckily Exec

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@fingolfin
Comment options

Answer selected by fingolfin
@kiryph
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants