user4964631
user4964631

Reputation: 41

Julia: Having a function f() containing the macro @printf, how can I access the output outside f()?

In the Julia NMF package a verbose option provides information on convergence using the @printf macro.

How can I access this output without rewriting the NMF package io?

To rephrase, having a function f() containing the macro @printf, how can I access the output outside f()?

Upvotes: 4

Views: 106

Answers (1)

Simon Byrne
Simon Byrne

Reputation: 7874

This does seem like useful functionality to have: I would suggest that you file an issue with the package.

However, as a quick hack, something like the following should work:

oldout = STDOUT
(rd,wr) = redirect_stdout()
start_reading(rd)

# call your function here

flush_cstdio()
redirect_stdout(oldout)
close(wr)
s = readall(rd)
close(rd)
s

Upvotes: 4

Related Questions