user2678074 user2678074 - 1 month ago 11
Python Question

Execute Robot Framework file from python script

from subprocess import call
import os

call(['robot '+os.getcwd()+'\\aaa.robot'])


file_dir: D:/aaa/test/aaa.robot

script for now in same dir

Output:
Traceback (most recent call last):
File "__init.py", line 7, in <module>
call(['robot '+os.getcwd()+'\\aaa.robot'])
File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 710, in __init_
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execut
startupinfo)
WindowsError: [Error 2] Nie mo┐na odnalečŠ okreťlonego pliku


I just cant handle it. I dont get why in python tunning anything is so complicated :(

I want same result as this line (written directly to cmd):

/>robot aaa.robot

jDo jDo
Answer

subprocess expects a list but you're inputting a string ('robot '+os.getcwd()+'\\aaa.robot').

Try:

call(['C:/Python27/python.exe', '-m', 'robot', 'D:/aaa/test/aaa.robot'])

or

call(['C:/Python27/Scripts/robot.bat', 'D:/aaa/test/aaa.robot'])