×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Running other applications from within Python

    Hi!

    I am building an application that uses the camera. I have a (stand-alone) camera application written in C that I want to use. Is there some way I can call the application from my python code?

    Something like the os.system() command in Python. For instance, if the executable of my other app is stored as 'take_image.exe' at 'c:\sys\bin', is it sufficient if I add the line :
    os.system('c:\sys\bin\take_image.exe')
    to my code so that it starts the other program?

    I do understand there is a more elegant way to embed C in Python, but I thought this would be the simplest way to get a prototype up.

    Thanks
    Kedar
    Last edited by kedarm; 2009-12-02 at 13:50.

  2. #2
    Nokia Developer Champion
    Join Date
    Jul 2008
    Location
    Pakistan
    Posts
    1,065

    Smile Re: Running other applications from within Python

    You can use e32 module like this
    Code:
    import e32
    e32.start_exe(u"c:\\sys\\bin\\my_app.exe","",1)
    Also , read here :
    How_to_open_another_application

    Best Regards,
    SajiSoft

  3. #3
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Running other applications from within Python

    Hi Sajisoft,

    Thanks a lot - it worked perfectly!

    Just curious - what does the "" and the 1 mean?

    Thanks
    Kedar

  4. #4
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Running other applications from within Python

    Quote Originally Posted by kedarm View Post
    Just curious - what does the "" and the 1 mean?
    According to the documentation:
    start_exe( filename, command [,wait])

    Launches the native Symbian OS executable filename (Unicode) and passes it the command string. When wait is set, the function synchronously waits for the exit of the executable and returns a value that describes the exit type. Possible values are 0 for normal exit and 2 for abnormal exit.

  5. #5
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Running other applications from within Python

    Hi!

    Is there a way to run Java code from Python?

    Something along the lines of e32.start_exe for .class files?

    Thanks
    Kedar

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Running other applications from within Python

    Quote Originally Posted by kedarm View Post
    Hi!

    Is there a way to run Java code from Python?

    Something along the lines of e32.start_exe for .class files?

    Thanks
    Kedar
    hmm kedar

    cant help you much but if you make a search in the Python dibo you will sure get something i remember properly that we have discussed this topic long back.

    Regards,

  7. #7
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,800

    Re: Running other applications from within Python

    Quote Originally Posted by kedarm View Post
    Hi!

    Is there a way to run Java code from Python?

    Something along the lines of e32.start_exe for .class files?

    Thanks
    Kedar
    Something called laa would work with 1.4.x versions.

    http://discussion.forum.nokia.com/fo...1&postcount=15
    Pankaj Nathani
    www.croozeus.com

  8. #8
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Running other applications from within Python

    Thanks a lot! The package laa seems to work fine.

    However, has anyone got it working specifically with Java jar files? I know this is a java issue, but just in case anyone has come across it while trying to use the laa package, please help.
    I have a jar file - how do I get or assign its UID?

    Thanks
    Kedar
    Last edited by kedarm; 2010-01-05 at 20:18.

  9. #9
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Running other applications from within Python

    UPDATE: Calling a Java midlet using laa extension

    I think I've figured it out. If anyone is following this thread, this is a solution I have found. It is rather inefficient, and if there is something better out there, please let me know

    Java applications built with the SDK before FP2 cannot be assigned pre-defined UID's (see this thread). Hence, before calling the execute function from the laa module, we need to determine the application UID.

    To do this, I wrote a small script that uses the applist module (see this wiki page). We parse through all the applications installed on the phone, find the UID of the relevant application and call it using laa. In my case, the name of the midlet was 'HelloMidlet' :
    Code:
    import applist, laa
    def lister():
    	a = applist.applist()
    	i = 0
    	while (1):
    		try :
    			if (str(a[i][1]) == u'HelloMidlet'):
    				return a[i][0]
    			else:
    				i = i+1
    		except IndexError :
    			return -1
    
    appuid = lister()
    if not (appuid==-1):
    	print "UID = ",appuid
    	laa.execute(appuid)
    else:
    	print "App not found"

  10. #10
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Running other applications from within Python

    I think I've figured it out. If anyone is following this thread, this is a solution I have found. It is rather inefficient, and if there is something better out there, please let me know
    Thanks for sharing your solution, Kedarm. No problem with your code. Of course people can try something more sophisticated than linear search if the list is big. If you want it more "pythonic", you could use:

    Code:
    app_uid = None
    for uid, caption, full_name in applist.applist():
        if caption == u'HelloMidlet':
            app_uid = uid
            break
    
    if app_uid:
        laa.execute(app_uid)
    else:
        print "App not found"

  11. #11
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Running other applications from within Python

    Hi!

    I'm having a bit of problem with the laa.execute function. The function appears to execute the application in a new thread.

    For instance, in the below script, the intended functioning is that I call an application (uid1) and it verifies identity. If authentication is successful, the application writes "1" to a file (say c:\\auth.txt), and if not, it writes "0".
    (the function readfile reads contents of a file - to reduce verbosity)
    Code:
    laa.execute(uid1)
    txt = readfile(u"c:\\results.txt")
    if (txt == u"1"):
    	laa.execute(uid2)
    else:
    	appuifw.note(u"Failed")
    But the problem on running the code is, the script doesn't wait for laa.execute(uid1) to finish. It continues to read from the file, and performs actions based on the present contents of the file. Is there any way to ensure that laa.execute() does not start off a new thread?

    I am aware that there are some workarounds - maybe delete the file beforehand (so that file exists only when uid1 is done), and put a try-except in an infinite while loop, but I was hoping for something more elegant.

    Is there documentation available for laa extension somewhere?
    Thanks

Similar Threads

  1. Please help installing Python libraries on S60
    By ericroijen in forum Symbian
    Replies: 11
    Last Post: 2009-07-18, 10:43
  2. Python for S60 1.9.2 released
    By tvijayan in forum Symbian
    Replies: 26
    Last Post: 2009-03-11, 09:28
  3. Replies: 1
    Last Post: 2007-06-17, 19:19
  4. symbian signed testing problem.
    By anglina in forum Symbian
    Replies: 0
    Last Post: 2007-02-01, 10:15

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×