Skip to content

Redirecting both stdout + stderror for Base.run results in an empty output when running multiple commands in sequence #46768

@cdsthreeline

Description

@cdsthreeline

Trying to run two commands in sequence, with redirected stdout + stderr using Base.pipeline, results in the second command's output being empty on MacOS 12.5.1 on a 2021 M1 Macbook Pro. This is an issue arises when using the M1-native version of Julia 1.8.1

MWE using 1.8.1, aarch64:

julia> module A 
       function f(command)
       stdout = IOBuffer()
       stderr = IOBuffer()
       
       run(pipeline(command; stdout, stderr))
       
       return String(take!(stdout))
       end
       
       function g()
       result1 = f(`echo 123`)
       result2 = f(`echo 456`)
       return result1, result2
       end
       end
Main.A

julia> A.g()
("123\n", "")

Curiously, only redirecting stdout seems to be fine

julia> module A 
       function f(command)
       stdout = IOBuffer()
       stderr = IOBuffer()
       
       run(pipeline(command; stdout, stderr))
       
       return String(take!(stdout))
       end
       
       function g()
       result1 = f(`echo 123`)
       result2 = f(`echo 456`)
       return result1, result2
       end
       end
Main.A

julia> A.g()
("123\n", "456\n")

Running on 1.8.1, x86-64 results in the correct output

julia> module A 
       function f(command)
       stdout = IOBuffer()
       stderr = IOBuffer()
       
       run(pipeline(command; stdout, stderr))
       
       return String(take!(stdout))
       end
       
       function g()
       result1 = f(`echo 123`)
       result2 = f(`echo 456`)
       return result1, result2
       end
       end
Main.A

julia> A.g()
("123\n", "456\n")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions