Problem using os.system()

Asked by Jason

I'm experiencing some problem using os.system()

this is my code:
import os

os.system('taskkill /f /im notepad.exe')

this is the error message I'm getting:
[error] Stopped
[error] An error occurs at line 3
[error] Error message: Traceback (most recent call last):
File "C:\Users\ADMINI~1\AppData\Local\Temp\sikuli-tmp4213322176460126939.py", line 3, in
os.system('taskkill /f /im notepad.exe')
File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\os.py", line 726, in system
File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 456, in call
File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 755, in __init__
File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 1240, in _execute_child
TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'

Similar thing happens when I try to use os.system to execute a batch file. Do you know what the problem is?
The strange thing is that this worked once, then it stopped working again.

Question information

Language:
English Edit question
Status:
Expired
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

Revision history for this message
Jason (jasonyoo) said :
#1

This works perfectly fine on my XP machine, but not on Vista 32 and 7 64.

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

The Jython 2.5.1 interpreter has some problems with blanks in strings at the interface to the the Windows system. This might be the problem here with Win 7 64.

Have a look at os.popen() instead.

Revision history for this message
Jason (jasonyoo) said :
#3

Thanks RaiMan, that solved my question.

Revision history for this message
Jason (jasonyoo) said :
#4

It worked couple times that I thought it fixed the problem, but os.popen() has exactly the same issue.

Is there another way you can run a batch file on Vista 32 & Win 7 in Sikuli?

Revision history for this message
Jason (jasonyoo) said :
#5

Sometimes when I restart the Sikuli-IDE, popen works... It's so strange...

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

You might simulate the "open start button" short-cut open a command window and paste()+Key.ENTER the command or open a prepared .bat, that is linked on the desktop by double clicking it ... I'm sure there are some other options.

Revision history for this message
Jason (jasonyoo) said :
#7

For some crazy reason... This works for me:
import os
try:
   os.system('taskkill /f /im notepad.exe')
except:
   print "Failed"

It always close notepad now... I don't know why... Thanks anyways.

Revision history for this message
Jason (jasonyoo) said :
#8

OK, now I know exactly what's happening.
os.system() or os.popen() have problem with Sikuli if you run it using:
"C:\Program Files\Sikuli X\Sikuli-IDE.exe"

If you launch Sikuli using the bat file, this solves the problem:
"C:\Program Files\Sikuli X\Sikuli-IDE-w.bat"

What is the difference between the two?

I really hope that I can get it working with launching the .exe instead of the .bat.

Please help!!!

Revision history for this message
Launchpad Janitor (janitor) said :
#9

This question was expired because it remained in the 'Open' state without activity for the last 15 days.