Running Julia .jl files
Asked Answered
G

7

101

I'm new to julia and just finished my first program. I wrote the code in julia-studio and have been testing it within that program. It gives me all of the correct output, but the shell separates the output as if it is two different executions.

I'm wondering if it's a problem with my compiler, so I thought I would try compiling it in the default julia shell found at julialang.org.

However, I cannot understand and/or figure out how to run it there. My current program reads input from another file in the same directory and outputs the results.

Can anyone explain how to run the program. This http://julia.readthedocs.org/en/latest/manual/getting-started/ isn't making sense to me.

Example output:

 julia> program
 #
 #
 #
 #


 julia> 
 #
 #
 #
 #
 #

The # represents integer numbers. Ideally the output should not be seperated by "julia>"

Gloxinia answered 7/3, 2014 at 2:58 Comment(0)
S
140

If you want to run the julia script from a command line then just do

/path/to/julia script-name.jl

In the shell of your choice.

If you want to run it from the julia repl then you want something like so:

julia> include("path/to/script-name.jl")

As to why your output is split like that I think we would need to see your code.

Salvation answered 7/3, 2014 at 3:52 Comment(7)
Thanks, this helped a lot. Well, it helped me realize I wasn't crazy. It appears I had downloaded the "prerelease" version of Julia 0.3. I downloaded an earlier version and used the julia.bat as the default program. Command prompt displayed all of the output correctly.Gloxinia
How do I add julia to path? I cannot even find the installation file in my C drive?Unnecessarily
Was too hard to find such a simple answer.Tourism
Is there a trick to run 'julia' in the background and save the log file? I've tried to run a .jl script on 'shell' using nohup, but the file 'nohup.out' is just empty. ThanksInterstratify
in windows you just need to add the julia.exe path to the PATH variable, and it can be just julia script-name.jlOrthodontia
best answer. i was attempting to call julia script via julia REPL, this sucks. Thank you JeremyAcrylonitrile
In windows include(raw"path/to/script-name.jl") will be more appropriate. raw takes care of both / and \.Everara
A
11

You can chmod your script and put the path to the julia binary at the to line.

Consider the following simple script hello.jl

#!/usr/bin/julia
println("Hello world")

change permission on the script using

chmod a+x hello.jl

Run the script using ./hello.jl

August answered 21/2, 2016 at 9:46 Comment(5)
0.5.0 version seems to store it somewhere else: bash: ./hello.jl: /usr/bin/julia: bad interpreter: No such file or directory, any idea of where to find it?Decanal
On OS X if you use the built-in installer, it's at /Applications/Julia-0.5.app/Contents/Resources/julia/bin/julia. Best is indeed to make a soft link to the binary.Tirade
It's better to use #!/usr/bin/env julia to avoid problems with the exact julia locationBolzano
julia1.1 on centos7. I tried as suggested. Path has entry /opt/julia/julia-1.1.0/bin/julia. Invoking Julia at terminal brings Julia prompt. Test.jl content: line1:#! /opt/julia/julia-1.1.0/bin/julia line2:println ("terminal invoke test"). Changed permission chmod +x /root/Test.jl #julia /root/Test.jl prints the line. But, #. /root/Test.jl is interpreted as shell script. Please guide me in resolving the issue!Sarver
Removing dot (.) at start of command resolves the issue of treating as shell script.Sarver
C
4

step 1: Open terminal

step 2: go to your Julia file location

step 3: execute the julia file

/path/to/folder script-julia.jl

Hit the up arrow, if it helps you. Thank you.

Castoff answered 23/7, 2019 at 9:49 Comment(0)
S
3

Look into using IJulia w/in Jupyter Notebook: https://github.com/JuliaLang/IJulia.jl

Stumpage answered 5/12, 2014 at 6:22 Comment(1)
Not really an answer to the question, but a helpful suggestion nonetheless if user1748681 hasn't tried it yet.Kuehnel
U
1

You're using the REPL. That works, but what I do is to go to command line and navigate to the folder like this (this is specifically for me, you will need to find the path directory to your file):

cd\users\yourname\desktop\code\julia

and to run the program:

julia filename.jl

its this simple (I guess)

Unaneled answered 11/10, 2021 at 18:18 Comment(1)
Btw I use Windows OS so it may not work if you have Linux or MacOSUnaneled
C
0

You also can use IntelliJ IDEA with the plugin of Julia ... That's a surprise

Cyclamen answered 28/4, 2019 at 8:48 Comment(0)
I
0

if you want to import a Julia file to another Julia file, you should use the following command:

include("path-to-your-file.jl")
Intraatomic answered 18/12, 2021 at 7:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.