Force interactive?


#1

dear julia experts—Is it possible to to invoke julia in batch but still receive the output as if the session was interactive REPL? maybe this could be done by tricking the session into thinking it is interactive, even though stdin comes from a file. for example, if my script ‘a.jl’ contains

x=[1,2,3]
x+22

I want to see (or construct) an output ‘a.log’ that looks like

julia> x=[1,2,3]
3-element Array{Int64,1}:
 1
 2
 3
julia> x+22
3-element Array{Int64,1}:
 23
 24
 25

I am thinking of using the Unix expect command, but this one has its own drawbacks, not the least of which is that julia prompts in boldface and I do not know how to turn this off. (julia --color=off does not turn off boldfacing afaics.)

(the use for this feature is to write tests for interactive sessions.)

advice appreciated.

regards,

/iaw


#2
$ echo 1 + 2 | julia -i
3

#3

hi stefan—I had written a response why julia -i < a.jl does not work, but then decided to try, on the spur of the moment, cat a.jl | julia -i. The latter works, the former does not. I always thought the two were completely identical and indistinguishable from the perspective of the receiving program. (how does julia know the difference??) thanks. solves my problem.

/iaw


#4

almost. the trailing semi-colon that suppresses output seems to be ignored. can this be fixed?

$ echo "rand(2);" | julia -i
2-element Array{Float64,1}:
 0.60601
 0.685653

one way to avoid this is to replace any ‘;’ ending statements with

$ echo "rand(2);print()" | julia -i

#5

They’re distinguishable: pipe versus file. However they should both work so please do file an issue.


#6

hi stefan—is it a buglet or intended behavior that a trailing semicolon does not suppress result output in “batch -i”?


#7

Not sure. Might as well mention it in the same issue.


#8

will do later today.