Skip to content

redirect_stdout does not redirect output from ccall #31236

@GregPlowman

Description

@GregPlowman

I'm not sure if redirect_stdout is supposed to redirect the output from a ccall, but it appears that it doesn't. I don't know where the output goes but it is not redirected and is not displayed to the terminal.

The docs do suggest that C output should be redirected:

help?> redirect_stdout
search: redirect_stdout redirect_stdin redirect_stderr

  redirect_stdout([stream]) -> (rd, wr)

  Create a pipe to which all C and Julia level stdout output will be redirected. Returns a tuple (rd, wr) representing the pipe ends. Data written to stdout may now be read from the rd end of the
  pipe. The wr end is given for convenience in case the old stdout object was cached by the user and needs to be replaced elsewhere.

Here's an example, using a function from RNGTest package which executes ccall.

First, the normal output without redirection:

Julia-1.1.0> using Random, RNGTest

Julia-1.1.0> rng = RNGTest.wrap(MersenneTwister(), UInt64);

Julia-1.1.0> RNGTest.smallcrushTestU01(rng)

========= Summary results of SmallCrush =========

 Version:          TestU01 1.2.3
 Generator:
 Number of statistics:  15
 Total CPU time:   00:00:12.17

 All tests were passed

Now with redirection:

Julia-1.1.0> rd, wr = redirect_stdout()
(Base.PipeEndpoint(Base.Libc.WindowsRawSocket(0x00000000000003f4) open, 0 bytes waiting), Base.PipeEndpoint(Base.Libc.WindowsRawSocket(0x00000000000003f0) open, 0 bytes waiting))

Julia-1.1.0> println("this is line 1")

Julia-1.1.0> RNGTest.smallcrushTestU01(rng)

Julia-1.1.0> println("this is line 2")

Julia-1.1.0> readline(rd)
"this is line 1"

Julia-1.1.0> readline(rd)
"this is line 2"

Metadata

Metadata

Assignees

No one assigned

    Labels

    ioInvolving the I/O subsystem: libuv, read, write, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions