1

I'm new to swift and I'm trying to run a Python file from it.

I already got the full path to the file, and my tries with NStask failed so far.

Now I'm somehow stuck launching the python executable with the path to the script as a parameter :-/ I already thought of just creating an .sh file with the appropriate command in it (python $filename) and launch that, but isn't there another way?

Of course I'm running OS X 10.10

Thanks for any help!

Michael
  • 289
  • 2
  • 5
  • 14

1 Answers1

3

This should work:

system("python EXECUTABLE_PATH")

Josh

  • Thank you Josh - Alright... so no NStask at all or how does that "system" work? --- Will try it tomorrow when I'm back at work ;-) – Michael Jul 06 '15 at 17:15
  • `system()` is a BSD library function, so you'll be able to get the documentation through `man system`. This link (showing how to get the output) might be useful to you: http://practicalswift.com/2014/06/25/how-to-execute-shell-commands-from-swift/ – Joshua Lee Tucker Jul 06 '15 at 18:15
  • is there a way to show the window of the terminal which got opened? Right now it's just writing in the console (which I can't see when I'd compile the app) – Michael Jul 08 '15 at 11:38
  • You can, but you'd have to use NSAppleScript. You're probably better off writing your own interface. P.S. next time you might want to be more specific with your question. – Joshua Lee Tucker Jul 09 '15 at 00:12