dopatraman
dopatraman

Reputation: 13908

How do I pipe the output of a unix command to a Julia script?

I'm trying to utilize the STDIN construct with Julia to read in the output of a unix command:

#!/usr/bin/julia
readline(STDIN)

Then in my terminal:

$ cat myfile.txt | ./pipe.jl

but I am not getting any output. What am I doing wrong?

Upvotes: 1

Views: 136

Answers (2)

mbauman
mbauman

Reputation: 31342

You're not doing anything with the result of readline(STDIN). What kind of output do you want?

Unlike the interactive REPL, a Julia script won't automatically print results. You need to explicitly print the resulting string:

print(readline(STDIN))

Upvotes: 5

Top Sekret
Top Sekret

Reputation: 758

The line:

#!/usr/bin/julia

Has to be first, as Unix reads only the first line and checks it for #!. Also, you need to do:

chmod +x pipe.jl

To make it work from ./pipe.jl construct.

Upvotes: 0

Related Questions