95

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>"

Saro Taşciyan
  • 5,210
  • 5
  • 31
  • 50
user1748681
  • 1,127
  • 1
  • 8
  • 9

7 Answers7

136

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.

Jeremy Wall
  • 23,907
  • 5
  • 55
  • 73
  • 2
    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. – user1748681 Mar 07 '14 at 04:35
  • How do I add julia to path? I cannot even find the installation file in my C drive? – Pragyaditya Das Apr 04 '16 at 09:51
  • Was too hard to find such a simple answer. – djangofan Oct 10 '18 at 22:19
  • 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. Thanks – godines Feb 05 '20 at 16:10
  • in windows you just need to add the julia.exe path to the PATH variable, and it can be just **julia script-name.jl** – NMech Aug 15 '20 at 20:00
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

Fredrik Bagge
  • 1,351
  • 8
  • 20
  • 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? – nightcod3r Sep 23 '16 at 01:20
  • 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. – Sebastian Good Sep 25 '16 at 16:29
  • 8
    It's better to use `#!/usr/bin/env julia` to avoid problems with the exact julia location – Dima Mironov May 16 '17 at 10:17
  • 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! – AVA Apr 13 '19 at 11:35
  • Removing dot (.) at start of command resolves the issue of treating as shell script. – AVA Apr 13 '19 at 12:58
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.

Hariharan AR
  • 1,386
  • 11
  • 20
3

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

Gideon
  • 989
  • 1
  • 11
  • 17
  • Not really an answer to the question, but a helpful suggestion nonetheless if user1748681 hasn't tried it yet. – beOn Oct 09 '15 at 02:28
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)

FireFlower
  • 53
  • 5
0

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

BertKing
  • 513
  • 5
  • 13
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")
TheHai
  • 31
  • 2