julia> run(`cd ..`)
ERROR: IOError: could not spawn `cd ..`: no such file or directory (ENOENT)
Stacktrace:
[1] _jl_spawn(::String, ::Array{String,1}, ::Cmd, ::Tuple{RawFD,RawFD,RawFD}) at ./process.jl:370
[2] (::getfield(Base, Symbol("##499#500")){Cmd})(::Tuple{RawFD,RawFD,RawFD}) at ./process.jl:512
[3] setup_stdio(::getfield(Base, Symbol("##499#500")){Cmd}, ::Tuple{RawFD,RawFD,RawFD}) at ./process.jl:493
[4] #_spawn#498(::Nothing, ::Function, ::Cmd, ::Tuple{RawFD,RawFD,RawFD}) at ./process.jl:511
[5] _spawn at ./process.jl:507 [inlined]
[6] #run#509(::Bool, ::Function, ::Cmd) at ./process.jl:669
[7] run(::Cmd) at ./process.jl:668
[8] top-level scope at none:0
很奇怪是不是,虽然我知道可以通过cd("xxx")来切换路径,但这会导致current working directory发生改变,导致后面会出现不可预见的问题。
cd(f::Function, dir::AbstractString=homedir())
Temporarily change the current working directory to dir, apply function f and finally return to
the original directory.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> pwd()
"/home/JuliaUser"
julia> cd(readdir, "/home/JuliaUser/Projects/julia")
34-element Array{String,1}:
".circleci"
".freebsdci.sh"
".git"
".gitattributes"
".github"
⋮
"test"
"ui"
"usr"
"usr-staging"
julia> pwd()
"/home/JuliaUser"