JohnSundell / ShellOut

Easily run shell commands from a Swift script or command line tool
MIT License
872 stars 85 forks source link

No such file or directory error using "at:" property #12

Closed darthpelo closed 6 years ago

darthpelo commented 7 years ago

Today I tried to use the at property to one of my script, but the result was always: /bin/bash: line 0: cd: ~/foldername: No such file or directory

So I copied&pasted the example from the README.md file, just to figure out my error, but the result is the same:

import ShellOut

do {
  try shellOut(to: ["mkdir NewFolder", "echo \"Hello again\" > NewFolder/File"])
  let output = try shellOut(to: "cat File", at: "~/NewFolder")
  print(output) // Hello again
}
catch {
  let error = error as! ShellOutError
  print(error.message) // Prints STDERR
  print(error.output) // Prints STDOUT
}

/bin/bash: line 0: cd: ~/NewFolder: No such file or directory.

I'm missing something? My marathon is update (also ShellOut) and I use it a lot without any others issues :)

Thanks!

muukii commented 6 years ago

@darthpelo I think you can not use ~. ~ depends on running user. Or, ShellOut may don't standardize path. Please try to use an absolute path.

JohnSundell commented 6 years ago

The problem is that ShellOut encloses the path passed using at: in quotes, which causes cd to fail to interpret it. The reason it does so is to support passing a path that contains spaces, but I think a better solution here would just be to escape the spaces.

darthpelo commented 6 years ago

Thanks @JohnSundell 👍