# Detect if running as script

**URL:** <https://discourse.julialang.org/t/detect-if-running-as-script/8818>\
**Category:** General Usage\
**Created:** [February 4, 2018, 8:22pm UTC](https://discourse.julialang.org/t/detect-if-running-as-script/8818 "2018-02-04T20:22:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)\
**Post date:** [February 4, 2018, 8:22pm UTC](https://discourse.julialang.org/t/detect-if-running-as-script/8818/1 "2018-02-04T20:22:27Z")

</div>

Does Julia have an equivalent to Python’s

```
if __name__ == " __main__":
    ...

```

Specifically, my problem is the following. I’m writing a standalone Julia script `run_simulation.jl` that does some computation and will ultimately run on a cluster. All the code in the script is in functions, including a function `main(args)`, and the only line in the script that actually runs code is the last line

```
main(ARGS)

```

Now, during testing on small datasets, I’m getting a bit annoyed at the JIT-overhead. So, I’d rather run an interactive julia session, and do e.g.

```
julia> include("run_simulation.jl")
julia> main(["./runfolder"])

```

Then I can repeatedly run `main` without Julia recompiling.

This works if I comment out the last line of the script, but out of curiosity: can Julia detect whether it’s running as a script and should execute the `main` function, or whether it is `include`d in the REPL (or another file)?

---

<div class="post-metadata">

**Author:** ![jkbest2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jkbest2/32/7350_2.png) [@jkbest2](https://discourse.julialang.org/u/jkbest2)\
**Post date:** [February 4, 2018, 8:33pm UTC](https://discourse.julialang.org/t/detect-if-running-as-script/8818/2 "2018-02-04T20:33:41Z")

</div>

Would `isinteractive` do what you need?

[https://docs.julialang.org/en/stable/stdlib/base/#Base.isinteractive](https://docs.julialang.org/en/stable/stdlib/base/#Base.isinteractive)

---

<div class="post-metadata">

**Author:** ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)\
**Post date:** [February 4, 2018, 8:50pm UTC](https://discourse.julialang.org/t/detect-if-running-as-script/8818/3 "2018-02-04T20:50:18Z")

</div>

Yes it would! Thanks!

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [February 4, 2018, 8:51pm UTC](https://discourse.julialang.org/t/detect-if-running-as-script/8818/4 "2018-02-04T20:51:35Z")

</div>

Old x-ref: [https://groups.google.com/d/msg/julia-users/ufpi8tV7sk8/-Uv0rtAWTWsJ](https://groups.google.com/d/msg/julia-users/ufpi8tV7sk8/-Uv0rtAWTWsJ)

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [February 5, 2018, 3:19am UTC](https://discourse.julialang.org/t/detect-if-running-as-script/8818/5 "2018-02-05T03:19:50Z")

</div>

Just be careful that it does not at all do the same thing as ` __name__ ` in python.
