paste doesn't work sometimes

Asked by Ju1+i-我.

hi all

environment : win10, java8, sikuli 1.1.0

I wrote some .py files that I want to run through command line,
here is a part of codes :
     1: self.fileCommon.openFile("cmd")
     2: paste("cd " + self.cmdPath)
     3: wait(2)
     4: type(Key.ENTER)
     5: wait(2)
     6: paste("python " + self.srmMany + " " + b + " " + a + " " + " E29")
     7: wait(2)
     8: type(Key.ENTER)
     9: wait(7)
    10: paste("exit")
    11: wait(2)
    12: type(Key.ENTER)
    13: wait(2)

when i run it , paste doesn't work sometimes ,
sometimes doesn't execute line2,the script continues to run just like nothing happened
but sometimes line 10 deesn't work ....

could you please help me to solve it ?
thanks so much!!!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Ju1+i-我.
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

I guess:
 1: self.fileCommon.openFile("cmd")

opens some GUI, where the paste() should fill in.

You have to somehow wait for the GUI to be ready, e.g. insert a dumb wait(1) or a more intelligent wait(someImage, 10), that if found signals the GUI to be ready.

Revision history for this message
Ju1+i-我. (1ju2+i-a.) said :
#2

thanks so much ,
but
1: self.fileCommon.openFile("cmd")
here is ok , only " paste " function doesn't work sometimes....

------- self.fileCommon.openFile("cmd")
---- This is the method of encapsulation.

    def openFile(self, path):
        self.log.write_log("FileOrFolderCommon -> openFile start.")
        self.log.write_log("path = %s"%(path))
        wait(1)
        type("r", Key.WIN)
        wait(1)
        if exists(Pattern("1515739915973.png").targetOffset(-75,45)):
            wait(2)
            paste(path)
            wait(2)
            type(Key.ENTER)
            wait(5)
        else:
            wait(1)
            paste(path)
            wait(2)
            type(Key.ENTER)
            wait(5)
        self.log.write_log("FileOrFolderCommon -> openFile end.")

do you have other idea?
thanks a lot

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

1: self.fileCommon.openFile("cmd")
here is ok , only " paste " function doesn't work sometimes....

... looks so, but might not be in the sense I mentioned:
you have dumb wait(5) after triggering the run box from the start menu.

An intelligent wait would be, to wait for something whatever related to the opened stuff, that signals, that its GUI is ready to accept a paste.

If this for some reason sometimes takes more than 5 seconds, paste would fail in this case.

Revision history for this message
Ju1+i-我. (1ju2+i-a.) said :
#4

thx a lot