# How to make an executable work on different machines (make a dynamic path)?

**URL:** https://discourse.julialang.org/t/how-to-make-an-executable-work-on-different-machines-make-a-dynamic-path/78236
**Category:** General Usage
**Tags:** question, package-compiler
**Created:** [March 21, 2022, 7:26pm UTC](https://discourse.julialang.org/t/how-to-make-an-executable-work-on-different-machines-make-a-dynamic-path/78236 "2022-03-21T19:26:53Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [March 21, 2022, 7:26pm UTC](https://discourse.julialang.org/t/how-to-make-an-executable-work-on-different-machines-make-a-dynamic-path/78236/1 "2022-03-21T19:26:53Z")

</div>

I have created a project folder `TESTEXE` and built an executable as below:  
 ![2](https://global.discourse-cdn.com/julialang/original/3X/3/1/31024949ec319f99fb393cd55a5b6cf6a90dc4a2.png)

```julia
module testexe

Base.@ccallable function julia_main()::Cint
    try
        testApp()
    catch
        Base.invokelatest(Base.display_error, Base.catch_stack())
        return 1
    end
    return 0
  end

  function testApp()
    filehandle = open("$(@ __DIR__ )/input.txt", "w")
    write(filehandle, "Hello world!")
    close(filehandle)
  end 
end # module

```

1- When I click on the executable it creates a txt file `input.txt` in the folder of the source file `./src/input.txt` . Can the txt file be generated in the same folder of executable? so then I only need the generated folder to use it in another machine.  
2- The project folder is located in the directory `C:\` . When I moved it to desktop `C:\Users\amroa\OneDrive\Desktop\testexe` , running the executable don’t generate the txt file in the folder of the source file. What should I do to handle this issue to make the executable works on different folders and machines?

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [March 22, 2022, 10:48am UTC](https://discourse.julialang.org/t/how-to-make-an-executable-work-on-different-machines-make-a-dynamic-path/78236/2 "2022-03-22T10:48:55Z")

</div>

Only trying to answer your first question. I tested your MWE with the following instrumentation:

```julia
function testApp()
    println("$(@ __DIR__ )/input.txt")
    filehandle = open("$(@ __DIR__ )/input.txt", "w")
    write(filehandle, "Hello world!")
    close(filehandle)
end 

```

and it seems `@ __DIR__ ` references the source directory of your application. If you change the `open` call to

```julia
filehandle = open("input.txt", "w")

```

the file will be created in your current working directory. I then tried to get the command line parameters via `ARGS` with

```julia
Base.@ccallable function julia_main()::Cint
    println("$ARGS")
    try
        testApp()
    catch
        Base.invokelatest(Base.display_error, Base.catch_stack())
        return 1
    end
    return 0
end

```

yielding

```julia
String[]

```

So it seems to me your best bet is to use [file system functions](https://docs.julialang.org/en/v1/base/file/), especially `cd` to dynamically manipulate your working directory.

P.S.: working with ‘PackageCompiler’ is rather time consuming. Building this simple example lasts between 2 minutes (incremental) to 5 minutes (full) on my machine…

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [March 23, 2022, 10:32pm UTC](https://discourse.julialang.org/t/how-to-make-an-executable-work-on-different-machines-make-a-dynamic-path/78236/4 "2022-03-23T22:32:46Z")

</div>

`pwd`

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [March 23, 2022, 10:35pm UTC](https://discourse.julialang.org/t/how-to-make-an-executable-work-on-different-machines-make-a-dynamic-path/78236/5 "2022-03-23T22:35:00Z")

</div>

> [@Amro](#):
>
> What is the file system function to print the current directory, is it `cd` ?

`cd` is C(hange)D(irectory).  
`pwd` is P(rint)W(orking)D(irectory).

You probably need something like `println(pwd())` to show the current directory in the console and `directoryAtRuntime = pwd()` in your code snippet.

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [March 25, 2022, 7:34am UTC](https://discourse.julialang.org/t/how-to-make-an-executable-work-on-different-machines-make-a-dynamic-path/78236/7 "2022-03-25T07:34:51Z")

</div>

> [@Amro](#):
>
> it shows up and disappears very fast

Do you run your executable from Windows explorer? I’d recommend to use Windows command prompt, because then you’ll be able to inspect the `stdout` and `stderr` output of your program

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [March 25, 2022, 12:46pm UTC](https://discourse.julialang.org/t/how-to-make-an-executable-work-on-different-machines-make-a-dynamic-path/78236/9 "2022-03-25T12:46:34Z")

</div>

> [@Amro](#):
>
> ```julia
> directoryAtRunTime = pwd()
> childdirectory= joinpath(directoryAtRuntime, "childfolder")
> 
> ```

Sorry, didn’t see it the first time around: Julia uses case sensitive variable names. `directoryAtRuntime` differs from `directoryAtRunTime`.

---

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [March 25, 2022, 12:49pm UTC](https://discourse.julialang.org/t/how-to-make-an-executable-work-on-different-machines-make-a-dynamic-path/78236/10 "2022-03-25T12:49:00Z")

</div>

Oops, I am sorry to make this typo. I checked it works fine.  
Thank you very much…
