calling python script from servoy

Questions, tips and tricks and techniques for scripting in Servoy

calling python script from servoy

Postby irene.meyer1422261887 » Sun May 07, 2017 2:04 pm

Hi,

I try to call a python script with an Applescript.

Code: Select all
var script = do shell script "python /Users/meyer/Documents/Projects/WoFOG/Code_Antonio/Loader_tracker.py -p /Users/meyer/Documents/Projects/WoFOG/ExpFolder/3001"
application.executeProgram('osascript',['-e',script ])


While the is working in ScriptEditor in servoy it does nothing. I don't even get an error and nothing is in the servoy.log.

It seams quite strait forward to me and I have not a clou why it doesn't work.

I would be grateful for any help.
User avatar
irene.meyer1422261887
 
Posts: 34
Joined: Mon Jan 26, 2015 10:44 am

Re: calling python script from servoy

Postby ROCLASI » Sun May 07, 2017 2:51 pm

Hi Irene,

application.executeProgram() doesn't allow spaces in the argument values. You need to put every argument in the array as it's own entry.
Also you don't have to use osascript to execute python. Just point to /usr/bin/python as your program.
So your code can look like this:
Code: Select all
application.executeProgram("/usr/bin/python", ["/Users/meyer/Documents/Projects/WoFOG/Code_Antonio/Loader_tracker.py", "-p", "/Users/meyer/Documents/Projects/WoFOG/ExpFolder/3001"])


Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: calling python script from servoy

Postby irene.meyer1422261887 » Mon May 08, 2017 8:21 am

Hi Robert,

Thank you for helping, unfortunately it doesn't work. I already tried that one as many others but it seems I can't do the magic.

Just to be sure I tried your code on a simple python app that adds a new folder to a directory, but while it is working thru the terminal it doesn't work with executeProgram.
Code: Select all
application.executeProgram("/usr/bin/python", ["/Users/meyer/Documents/Projects/WoFOG/Code_Antonio/try.py"])


What I don't understand is that it doesn't return an error or some other kind of message, it is like that rule doesn't run. I tried many other ways, like make an .sh and call it, at least it returned a "permission denied" in the log. Now I know that Apple's integrity check is getting worst by the day, bit I don't want to disable it.

application.executeProgram() doesn't allow spaces in the argument values.

Probably I understand it the wrong way, but why is this working? It looks likes a lot of spaces to me :o
application.executeProgram('osascript',['-e','tell application "Finder" to say "David"']);
User avatar
irene.meyer1422261887
 
Posts: 34
Joined: Mon Jan 26, 2015 10:44 am

Re: calling python script from servoy

Postby Andrei Costescu » Mon May 08, 2017 8:40 am

Some ideas:
  • surround your "application.executeProgram" with a try/catch and see if it doesn't throw an exception (also check app. server log maybe)
  • which user runs the Servoy process in the OS? Does it have all the necessary permissions for the file(s) that you want to use?
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm


Return to Methods

Who is online

Users browsing this forum: No registered users and 5 guests

cron