3

I use system() for executing a shell command in Swift. As read in the documentation return value should be 0, if successful or -1 if it failed. But I get 256 and execution seems to be successful.

There are some other questions related to magical value "256" but with different languages and no solutions/explanations.

I would add a comparison to 256 for success, but it would be better to know what happened and what else should be checked for success.

Added: Yes, I read this. And there are a lot of assumptions and guesses, but no explicit solution. And it is not Swift.

  • 2
    Possible duplicate of [Executing shell script with system() returns 256. What does that mean?](http://stackoverflow.com/questions/3736320/executing-shell-script-with-system-returns-256-what-does-that-mean) – Desdenova Aug 22 '16 at 14:27
  • Isn't `system()` deprecated nowadays, in favor of `posix_spawn()`? – dfrib Aug 22 '16 at 14:47
  • Possible duplicate: Yes, I read this. And there are a lot of assumptions and guesses, but no explicit solution. And it is not Swift. –  Aug 22 '16 at 14:53
  • A self-contained, reproducible example would be helpful. – Martin R Aug 22 '16 at 16:08
  • Realy simple, like let err = system("ls") if err == 0 || err == 256 { ... } –  Aug 22 '16 at 16:33
  • `system("ls")` returns `0` on my computer. – Martin R Aug 22 '16 at 17:27

0 Answers0