JuneBash
(June Bash)
1
I'm interested in writing a sort of replacement for Make (using a different Makefile syntax). From some cursory research it looks like Foundation.Process is going to be important for this, along with probably swift-argument-parser. However, I'd like to avoid using Foundation if possible. Is there any other way to run bash/zsh/etc commands from a Swift executable package?
2 Likes
You can use C's system, POSIX's popen, or POSIX's exec family of functions.
2 Likes
Looking at the swift-corelibs-foundation implementation for Linux, it appears that Foundation.Process uses posix_spawn internally.
1 Like
Diggory
(Diggory)
4
If your project is open source, perhaps you could lift Process wholesale from Foundation?
jeremyp
(Jeremy Pereira)
5
Please don't use system(). It runs he command in a shell, which is an unnecessary extra process and you don't have as much control over the environment as you might wish for.
1 Like
eskimo
(Quinn “The Eskimo!”)
6
Please don't use system.
It’s also a security vulnerability looking for a place to happen.
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple
4 Likes
tera
7
Interestingly there's no warning about a security vulnerability in the man page.
1 Like
jeremyp
(Jeremy Pereira)
8
That surprised me when I looked up system(3) in the man pages, and is why I didn't explicitly mention security in my plea. The Linux man page has detailed discussion about the security implications.
2 Likes
eskimo
(Quinn “The Eskimo!”)
9
Oh wow, that’s not good. I’ve filed a bug requesting that we add something about this (r. 106131057).
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple
4 Likes
popen (which was also mentioned) runs a shell as well.