The reasons for not using shell to use basic tasks in the language are not related to performance at all - it's more about safety and portability. You wouldn't use eval
in your language nor try to concatenate strings to create SQL queries - and yet there you are, creating shell commands by concatenating strings.
Brett Hale's "solution" conveniently doesn't mention all these and hides the code needed to make this safe and portable behind the comment "do it yourself" - in fact, when you do this you'll end up with more code than hand-rolled copy function and it'll still be buggy. And if you have a bug there, an user can inject commands (for example, run it with a destination file a_file" || rm -rf --no-preserve-root
). Also you're relying on the shell, which itself can have bugs (see Shellshock)
Calvin's answer correctly mentions why the copy operation done by the shell may work faster - it can do more tricks to make it look like it copies faster. In fact, there is no inherent magic in the shell copy operations. The "performance problem" is not a problem since the main bottleneck is in actual reading and writing.
Furthermore, you present a false dichotomy, since you fail to consider using a third option: a third-party library. One of them is Boost.Filesystem, which has a copy function.