Windows: How to open apps from specific path and switch between apps only knowing the process ids

Asked by Vinay Kulkarni

Hi,

I have windows application which is stored in d:\Packages\MyApp111122\MyApp.exe

MyApp requires configuration files to initiate. It automatically picks that file from current directory.

I have stored configuration file in d:\conf. It contains 10 directories namely c1, c2....c10. Each directory has configuration file.

So i need to call this application from configuration directory (e:\conf). I tried calling this from command prompt, it succeeds, but i am not able to create instance of that. I want to create multiple instances of the application. Instance is required me to switch between apps (focusing to any app of my choice)

Can somebody suggest me ideas.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

as already mentioned in our private conversation:

--- App.open()
cannot be used in your case, since it does not allow, to specify a start directory

--- os.popen()
can be used in combination with Window's start command, to start your app from one of your configuration directories, but it does not return an App instance, that can be used later

--- window title for app switching
If your different app instances do not have different window titles, you will not be able, to switch between these apps using Sikuli's switchApp() or App.focus().
If they have different window titles, use switchApp().

--- other possibilities
if the app window content makes them distinguishable, you might look for this and use alt-tab to switch the apps. Or you might use clicking the task bar to switch between the app instances, since they should stay there in the order they where started.

Revision history for this message
Vinay Kulkarni (vinay-s) said :
#2

All instances of application have same title. That’s why I am trying to create instance. I was looking at getting process id from windows os. Is there any method in python to get process id of app?

Thanks & Regards,
Vinay Kulkarni
Ishnatek Systems & Services Pvt. Ltd.
Contact : +91 8956345939

-----Original Message-----
From: <email address hidden> [mailto:<email address hidden>] On Behalf Of RaiMan
Sent: Wednesday, November 23, 2011 3:01 PM
To: <email address hidden>
Subject: Re: [Question #179709]: How to open any application from user defined path

Your question #179709 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/179709

    Status: Open => Answered

RaiMan proposed the following answer:
as already mentioned in our private conversation:

--- App.open()
cannot be used in your case, since it does not allow, to specify a start directory

--- os.popen()
can be used in combination with Window's start command, to start your app from one of your configuration directories, but it does not return an App instance, that can be used later

--- window title for app switching
If your different app instances do not have different window titles, you will not be able, to switch between these apps using Sikuli's switchApp() or App.focus().
If they have different window titles, use switchApp().

--- other possibilities
if the app window content makes them distinguishable, you might look for this and use alt-tab to switch the apps. Or you might use clicking the task bar to switch between the app instances, since they should stay there in the order they where started.

--
If this answers your question, please go to the following page to let us
know that it is solved:
https://answers.launchpad.net/sikuli/+question/179709/+confirm?answer_id=0

If you still need help, you can reply to this email or go to the
following page to enter your feedback:
https://answers.launchpad.net/sikuli/+question/179709

You received this question notification because you asked the question.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

This works on my Win7:

Needed to run successfully:
a folder c:\Tests containing 4 files test1.txt, test2.txt, test3.txt, test4.txt

What it does:
for ear of the above files a Notepad process is started and the process ids are stored in the sequence as the processes where started.
In the end pids contains the process ids in this order.
the last loop is to demonstrate, that the pids are in correct sequence

Hope it helps, to get a little bit further.

import os
s = Env.getOSUtil()
for i in range(4):
    os.popen(r'start /D "c:\Tests" notepad test'+str(i+1)+".txt")
    cmd = r'tasklist /FI "IMAGENAME eq notepad.exe" /FO csv /NH'
    ps = os.popen(cmd).readlines()
    pids = []
    for p in ps:
        #print p
        pid = int(eval("("+p+")")[1])
        print "ProcessID:", pid
        if not pid in pids:
            pids.append(pid)
for p in pids:
    s.switchApp(p, 0)
    s.getWindow(p).highlight(2)

Can you help with this problem?

Provide an answer of your own, or ask Vinay Kulkarni for more information if necessary.

To post a message you must log in.