JohnSundell / ShellOut

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

Error on Linux #6

Closed niklassaers closed 6 years ago

niklassaers commented 7 years ago

With Swift 3.1.1 on Ubuntu, I get the following error:

JohnSundell commented 7 years ago

Thanks for reporting this @niklassaers! I created this PR that should fix the problem 😄 https://github.com/JohnSundell/ShellOut/pull/7

JohnSundell commented 7 years ago

@niklassaers It seems like we have some more problems on Linux, all the tests are failing 😅 But if you use the latest released version instead of master, you at least shouldn't have that build error. With WWDC and new Xcode/Swift version to upgrade to, I won't have time to look into the test failures right now. Feel free to take a look if you want, otherwise I'll take care of it within the next few weeks 🙂

jorgealegre commented 7 years ago

Hi @JohnSundell . Do you know if there's a way around to this readabilityHandler problem on Linux? I know using a NotificationCenter for when data is available to be read is an option.

JohnSundell commented 7 years ago

@georgealegre Interesting. Can you tell me more about this approach?

jorgealegre commented 7 years ago

I have the same issue trying to run a program and reading its output as soon as it's available. It's running on a server thanks to the Kitura framework and the idea is to use websockets to broadcast the output. Using readibiltyHandler works for me on Mac but on Ubuntu I have the same issue as you. You can see my code here: GitHub

I've read on a bunch of SO posts about using notifications and reacting to those notifications but I can't get it to work. The function that should be receiving those notifications is never called. I assume it's an issue with threads but there isn't much info out there.

You can read about the solution I'm talking about here: StackOverflow

Maybe you can get it to work and share some insight with me in the process.

BTW, thanks for your amazing blog posts. I read them every week.

jorgealegre commented 7 years ago

@JohnSundell I've found the implementation of FileHandle for Foundation on Linux and it seems these things are still not implemented - FileHandle. Seems we have to wait a while. Using notifications won't work either since waitInBackgroundAndNotify() is also not implemented .

JohnSundell commented 7 years ago

Thanks for looking into this @georgealegre 👍 Seems like we'll need to revert back to the old technique used before https://github.com/JohnSundell/ShellOut/pull/3/files on Linux. It's also a requirement for using the new version of ShellOut for Marathon, since it also supports Linux - so I'll try to look into this ASAP.

JohnSundell commented 7 years ago

I've now worked around the error and merged my PR: https://github.com/JohnSundell/ShellOut/pull/7. ShellOut again works on Linux 🎉 Think this is good enough to close this issue for now, and we can revisit this again once the Swift standard library on Linux has caught up with its macOS equivalent in this regard 🙂 What do you think @georgealegre & @niklassaers?

jorgealegre commented 7 years ago

Seems ok. I'm not sure what your plans are with ShellOut. From the code I've read, it seems like it isn't meant for using input and output streams without closing the pipes or reading asynchronously. I'm not sure if I'm explaining myself correctly. For example, ShellOut wouldn't be able to run $ tail -f somefile since the STDOUT file would never be closed until the process is terminated. I'm even more screwed with my project 'cause the process I'm launching prompts the user for input while it's running.

JohnSundell commented 6 years ago

I would actually love for ShellOut to be able to hand continous/async output, but there's a separate issue for it here: https://github.com/JohnSundell/ShellOut/issues/11. Closing this one for now 😄 Thanks for all your input on this 👍