# Executing Packages and Directories

**URL:** <https://discourse.julialang.org/t/executing-packages-and-directories/34819>\
**Category:** General Usage\
**Created:** [February 18, 2020, 5:34pm UTC](https://discourse.julialang.org/t/executing-packages-and-directories/34819 "2020-02-18T17:34:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hieronimo](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hieronimo](https://discourse.julialang.org/u/hieronimo)\
**Post date:** [February 18, 2020, 5:34pm UTC](https://discourse.julialang.org/t/executing-packages-and-directories/34819/1 "2020-02-18T17:34:02Z")

</div>

In Python, one can run a program by package name, file name, directory name or zip file name. Also, one can run commands from stdin (e.g. by pipelines) [link](https://docs.python.org/3/using/cmdline.html)

In Julia, we can run commands from stdin but it isn’t mentioned in [docs](https://docs.julialang.org/en/v1/manual/getting-started/)! (I’m not sure! maybe somewhere else)  
For example, this is working:  
`echo 'println(sinpi(1/2))' | julia`  
in **Julia Version 1.3.0**  
**Commit 46ce4d7933 (2019-11-26 06:09 UTC)**

IMO, all that interfaces can be useful for some cases.  
I looked for any discussion but not found anything, so thought it would be good to discuss and decide whether Julia shoulds have them or not. 😉

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 18, 2020, 6:04pm UTC](https://discourse.julialang.org/t/executing-packages-and-directories/34819/2 "2020-02-18T18:04:58Z")

</div>

> [@hieronimo](#):
>
> run a program by package name

I am not sure what this means in the context of Julia packages, which usually contain type and method definitions, not toplevel code.

> [@hieronimo](#):
>
> run commands from stdin but it isn’t mentioned

Look for [`julia -e`](https://docs.julialang.org/en/v1/manual/getting-started/), which is somewhat simpler for short snippets, or simply `julia some_script.jl`.

---

<div class="post-metadata">

**Author:** ![hieronimo](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hieronimo](https://discourse.julialang.org/u/hieronimo)\
**Post date:** [February 18, 2020, 9:03pm UTC](https://discourse.julialang.org/t/executing-packages-and-directories/34819/3 "2020-02-18T21:03:02Z")

</div>

> [@Tamas\_Papp](#):
>
> I am not sure what this means in the context of Julia packages, which usually contain type and method definitions, not toplevel code.

For example, [youtube-dl](https://github.com/ytdl-org/youtube-dl) is a python package. you can install it by `python3 -m pip install youtube_dl` and use it by `python3 -m youtube_dl`  
Actually, python run ` __main__.py` file that located in the root directory of the package.  
[`youtube-dl`’s ` __main__.py` file](https://github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/ __main__.py).  
[`pip`’s ` __main__.py` file](https://github.com/pypa/pip/blob/master/src/pip/ __main__.py)

Most julia packages aren’t for end-user and i know that it’s a less popular feature but  
`julia -m <pkgname> <pkgarg1> <pkgarg2>`  
is nicer than  
`julia -e "using <pkgname>; main()" <pkgarg1> <pkgarg2>`

For Julia, it doesn’t have to be a file, it can be a specified function in the main module. and in anyway, it’s optional and can’t break compatibility.

> [@Tamas\_Papp](#):
>
> Look for [`julia -e`](https://docs.julialang.org/en/v1/manual/getting-started/), which is somewhat simpler for short snippets, or simply `julia some_script.jl` .

I agree with you they are better interfaces, using `cat <file> | julia` or `echo <str> | julia` are wrong indeed but if one has a program that generate some julia commands or want to run some online code, using pipelines could help. e.g. `curl <link> | julia`

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 19, 2020, 7:03am UTC](https://discourse.julialang.org/t/executing-packages-and-directories/34819/4 "2020-02-19T07:03:19Z")

</div>

Julia distinguishes [projects and packages](https://julialang.github.io/Pkg.jl/dev/glossary/). Here you are talking about projects that contain an application.

That functionality is WIP, but if you are interested in delivering an “executable” like [youtube-dl](https://github.com/ytdl-org/youtube-dl) (which is usually deployed as a python script in binary format), look at

[https://julialang.github.io/PackageCompiler.jl/dev/devdocs/binaries\_part\_2/](https://julialang.github.io/PackageCompiler.jl/dev/devdocs/binaries_part_2/)

(incidentally, I moved the topic from internals to Usage)
