On Saturday, June 28, 2014 10:29:35 PM UTC-4, Laszlo Hars wrote:
>
> Yes, it is a possibility, as I wrote above: "Maybe the solution is to
> pre-process the Julia code to be evaluated, to handle print() and
> multi-line input in several parse() calls." It is not trivial.
>
You can capture print output by redirecting stdio as I mentioned above
(just saving the original STDOUT in a variable so that you can still print
your final output to it). Multiline input can be handled by
Base.parse_input_line(STDIN), which is what the REPL uses to read multiline
input and works the same way (it detects if the line is the beginning of a
valid but incomplete expression and reads another line if so).
For example, try:
const orig_STDOUT = STDOUT
rdstdout, wrstdout = redirect_stdout()
while true
try
result = eval(Base.parse_input_line(STDIN))
println("RESULT = ", result)
catch e
print("EXCEPTION = ")
Base.showerror(STDOUT, e)
end
s = readavailable(rdstdout)
clipboard(s)
print(orig_STDOUT, s)
end