Passing argument value dynamically

Asked by Pritam Biswas on 2020-03-16

Hi,

I want to pass the height and width value of my current monitor screen to the opened terminal dynamically. How i can achieve thi? I've tried few syntax, seems it's not working.
Below is my snippet-
cmdPath = os.getenv("comspec")
SCREEN=Screen(0)
print(showMonitors())
r=SCREEN.getRect()
w=r.width
print(w)
h=r.height
print(h)
title = "My Command Line"
cmd = 'start "%s" %s'%(title, cmdPath)
os.popen(cmd);
wait(3)
type("mode con: cols=\"h\" lines=\"w\"")
type(Key.ENTER)
type("CD E:")
type(Key.ENTER)
type("CD E:\Pritam\SikuliXVer2.1.0-SNAPSHOT\DMO\ ")
type(Key.ENTER)
wait(1)
type("test.bat")
type(Key.ENTER)

type("mode con: cols=\"h\" lines=\"w\"")-----How i can pass the cols value and lines value dynamically as per h & w value?
Sikuli version- 2.0.3
Java- jdk 1.8

Regards,
Cris

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
2020-03-16
Last query:
2020-03-16
Last reply:
2020-03-16
Best Manfred Hampl (m-hampl) said : #1

This is absolutly not Sikuli-specific, buy plain Python.
See books or web pages about Python.
Topic: String concatenation.

Try

type("mode con: cols="+str(h)+" lines="+str(w))

or similar to your creation of "cmd = 'start ...'

modeCommand = 'mode con: cols=%s lines=%s'%(str(h),str(w))
type(modeCommand)

Pritam Biswas (pritam-b) said : #2

Thanks Manfred!!
Alternatively found the below soultion is also orking for me-
type("mode con: cols={0} lines={1}".format(h,w))

Pritam Biswas (pritam-b) said : #3

Thanks Manfred Hampl, that solved my question.