Skip to content

Commit

Permalink
run() now returns with stderr = NULL if stderr is redirected to
Browse files Browse the repository at this point in the history
stdout.

This also fixes an error when interrupting a `run()` with a redirected
standard error.
  • Loading branch information
gaborcsardi committed Sep 15, 2021
1 parent e18710b commit 12b2419
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# processx (development version)

* `run()` now sets `stderr` to `NULL` in the result (instead of an empty
string), if the standard error was redirected to the standard output.

# processx 3.5.2

* `run()` now does not truncate stdout and stderr when the output
Expand Down
4 changes: 2 additions & 2 deletions R/run.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ run <- function(
runcall <- sys.call()
resenv <- new.env(parent = emptyenv())
has_stdout <- !is.null(stdout) && stdout == "|"
has_stderr <- !is.null(stderr) && stderr %in% c("|", "2>&1")
has_stderr <- !is.null(stderr) && stderr == "|"

if (has_stdout) {
resenv$outbuf <- make_buffer()
Expand Down Expand Up @@ -279,7 +279,7 @@ run_manage <- function(proc, timeout, spinner, stdout, stderr,
start_time <- proc$get_start_time()

has_stdout <- !is.null(stdout) && stdout == "|"
has_stderr <- !is.null(stderr) && stderr %in% c("|", "2>&1")
has_stderr <- !is.null(stderr) && stderr == "|"

pushback_out <- ""
pushback_err <- ""
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-run.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test_that("stderr_to_stdout", {
expect_equal(out$status, 0L)
expect_equal(
out$stdout, paste0("o1e1o2e2", if (is_windows()) "\r", "\n"))
expect_equal(out$stderr, "")
expect_equal(out$stderr, NULL)
expect_false(out$timeout)
})

Expand Down

0 comments on commit 12b2419

Please sign in to comment.