# How to input path in run() and joinpath() on Windows

**URL:** <https://discourse.julialang.org/t/how-to-input-path-in-run-and-joinpath-on-windows/29183>\
**Category:** General Usage\
**Created:** [September 26, 2019, 4:12am UTC](https://discourse.julialang.org/t/how-to-input-path-in-run-and-joinpath-on-windows/29183 "2019-09-26T04:12:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leejm516](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leejm516/32/8219_2.png) [@leejm516](https://discourse.julialang.org/u/leejm516)\
**Post date:** [September 26, 2019, 4:12am UTC](https://discourse.julialang.org/t/how-to-input-path-in-run-and-joinpath-on-windows/29183/1 "2019-09-26T04:12:46Z")

</div>

Hello, everybody!

Today I have got in trouble with `run()` for putting the path from a string variable.

It seems ok with …

```julia
julia> test = joinpath("~")
"~"

julia> run(`dir $test`)
%APPDATA%
3D\ Objects
AppData
Application\ Data
Contacts
Cookies
Desktop
...
\354\213\234\354\236\221\ \353\251\224\353\211\264
Process(`dir '~'`, ProcessExited(0))

```

But it returns errors even though the “Desktop” directory exists.

```julia
julia> test = joinpath("~", "Desktop")
"~\\Desktop"

julia> run(`dir $test`)
dir: cannot access '~Desktop': No such file or directory
ERROR: failed process: Process(`dir '~\Desktop'`, ProcessExited(2)) [2]

Stacktrace:
 [1] pipeline_error at .\process.jl:813 [inlined]
 [2] #run#536(::Bool, ::typeof(run), ::Cmd) at .\process.jl:728
 [3] run(::Cmd) at .\process.jl:726
 [4] top-level scope at REPL[20]:1

julia>

```

In addition, this also returns an error:

```julia
julia> run(`dir "~/tmp/"`)
LICENSE.md binary deprecated external papers test
README.rst codecov.yml docs initCobraToolbox.m src tutorials
Process(`dir '~/tmp/'`, ProcessExited(0))

julia> run(`mkdir "~/tmp/t"`)
mkdir: cannot create directory '~/tmp/t': No such file or directory
ERROR: failed process: Process(`mkdir '~/tmp/t'`, ProcessExited(1)) [1]

Stacktrace:
 [1] pipeline_error at .\process.jl:813 [inlined]
 [2] #run#536(::Bool, ::typeof(run), ::Cmd) at .\process.jl:728
 [3] run(::Cmd) at .\process.jl:726
 [4] top-level scope at REPL[30]:1

julia>

```

Certainly, `mkdir` works well in `cmd` on windows.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [September 26, 2019, 6:04am UTC](https://discourse.julialang.org/t/how-to-input-path-in-run-and-joinpath-on-windows/29183/2 "2019-09-26T06:04:40Z")

</div>

does this help?  
[https://superuser.com/questions/332871/what-is-the-equivalent-of-linuxs-tilde-in-windows](https://superuser.com/questions/332871/what-is-the-equivalent-of-linuxs-tilde-in-windows)

overall, I think `run` would actually run the string you provide to it; otoh if you look at, for example, how `mkdir` works:  
[https://github.com/JuliaLang/julia/blob/9a1dbc038587c6072ac99699e416cbc8908054ed/base/file.jl#L171](https://github.com/JuliaLang/julia/blob/9a1dbc038587c6072ac99699e416cbc8908054ed/base/file.jl#L171)  
you will see that it calls different clib on windows. (that’s how Julia makes `File` works cross-platform so you don’t have to write ugly code yourself, by manipulating `/` `\` strings etc.)

So in your case, `~` is simply ‘not a thing’ on Windows.

---

<div class="post-metadata">

**Author:** ![zaki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zaki/32/10300_2.png) [@zaki](https://discourse.julialang.org/u/zaki)\
**Post date:** [September 26, 2019, 6:24am UTC](https://discourse.julialang.org/t/how-to-input-path-in-run-and-joinpath-on-windows/29183/3 "2019-09-26T06:24:46Z")

</div>

When working with paths, it is generally easier to use the functions in [`Base.FileSystem`](https://docs.julialang.org/en/v1/base/file/) for these kinds of things, i.e. use `homedir()` for `~` along with `readdir()` and `mkdir()`.  
This makes it easier to run code across platforms.

Also, for the mkdir example, try:

```julia
julia> run(`mkdir "~\\tmp"`)

```

It should make a folder named `~/tmp` starting from the current working directory. Probably not the intended effect.  
EDIT: So the mkdir example worked on one computer, but it failed on a different computer (both Win10). That’s probably because one computer had some build tools installed which over-ride some of the default windows commands (mkdir example worked on this one).

---

<div class="post-metadata">

**Author:** ![leejm516](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leejm516/32/8219_2.png) [@leejm516](https://discourse.julialang.org/u/leejm516)\
**Post date:** [September 26, 2019, 9:23am UTC](https://discourse.julialang.org/t/how-to-input-path-in-run-and-joinpath-on-windows/29183/4 "2019-09-26T09:23:15Z")

</div>

Thanks for reply, @jling and @zaki!. Actually, I want to run git with a path as an input parameter.

What I want to revise is: [https://github.com/opencobra/COBRA.jl/blob/develop/tutorials/tutorial-PALM.jl.ipynb](https://github.com/opencobra/COBRA.jl/blob/develop/tutorials/tutorial-PALM.jl.ipynb)

In that file,

```julia
installDir = "~/tmp/cobratoolbox"
run(`git clone --depth=1 --recurse-submodules https://github.com/opencobra/cobratoolbox.git $installDir`);

```

result in creation of “~” folder in pwd instead of seeking %userprofile%.

However, look at the following code:

`PALM(modelDir, "$(joinpath(dirname(pathof(COBRA)), "../test/scriptFile.m"))"; nMatlab=nWorkers, outputFile="modelCharacteristics.mat", varsCharact=varsCharact, cobraToolboxDir=installDir)`

This function gets the same parameter `installDir`, but this function does interpret “~” as %userprofile% on windows.

In that function, the following code is executed:

```julia
  if !isdir(cobraToolboxDir)
        cmd = "git clone git@github.com:opencobra/cobratoolbox.git $cobraToolboxDir"
        @info cmd
        run(`sh -c $cmd`)
    end

```

In conclusion, I am still not sure when the julia interpret tilde as %userprofile%.  
However, I think I can manage to this problem based on the above suggestions.

---

<div class="post-metadata">

**Author:** ![zaki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zaki/32/10300_2.png) [@zaki](https://discourse.julialang.org/u/zaki)\
**Post date:** [September 26, 2019, 9:46am UTC](https://discourse.julialang.org/t/how-to-input-path-in-run-and-joinpath-on-windows/29183/5 "2019-09-26T09:46:08Z")

</div>

I think Julia is just passing the tilde without interpreting it.  
The `git` and `sh -c` commands are interpreting it.  
Though on my system, neither version interprets `~` as home directory—both of them create a `~/tmp` folder starting from pwd.

EDIT: Tried it on the second computer, and the `sh -c` version works properly there (again an issue with different build tools). The specific `sh` command is bundled with git, and it interprets `~` as the home directory. This can be verified by running `where sh` and `sh -c "~"` in cmd.
