Windows: App.open("cmd.exe") does not open a new command window when running from command line --- use the start command instead with os.popen()

Asked by Lebron Jones

Problem is pretty straightforward. I am trying to run a sikuli script that opens up a command prompt window (sikuli is also being run from the command line). My code is as follows:

 cmdPath = os.getenv("comspec")
 cmdWindow= App.open(cmdPath )
 time.sleep(15)
 App.focus(cmdWindow)
 type("echo Hello")

However, instead of launching a new window (like it does with, say, Internet Explorer), it apparently opens a new cmd window inside the existing cmd window (again, I'm running Sikuli from the command line already). I get the following output:

[log] App.open C:\Windows\system32\cmd.exe(3420)
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Administrator>[log] App.focus C:\Windows\system32\cmd.exe(3420) #0
[error] App.focus failed: C:\Windows\system32\cmd.exe(3420) not found
[log] TYPE "echo Hello"
echo Hello

Any idea what is going on here?

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

tested on my Win7 32:

In an open command line window when giving the command "cmd", does generally not open a new command line window, but a sub session inside the current command line window. Both sessions share sys in and sys out (the printouts of both sessions get mixed up).

So this approach will not be successful when running the script from command line, if the intention is, to have a separate command line window.

You can use the start command to achieve what you want:

cmdPath = os.getenv("comspec")
title = "My Command Line"
cmd = 'start "%s" %s'%(title, cmdPath)
os.popen(cmd); wait(3)

this opens an extra command line window with the window title given with the title string, so you can focus on this window subsequently. This works in IDE and running from command line.

Revision history for this message
shawn kirsch (shawn-kirsch) said :
#2

I like this. pretty smart.

Revision history for this message
shawn kirsch (shawn-kirsch) said :
#3

It seems like the title has to be more than one word or it fails, any ideas?

Revision history for this message
shawn kirsch (shawn-kirsch) said :
#4

looks like the work around is this line after you launch the cmd window. It will rename the title.

type('title %s' %my_title)

Can you help with this problem?

Provide an answer of your own, or ask Lebron Jones for more information if necessary.

To post a message you must log in.