5
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
3
  • What is it you're hoping this program will do? Commented Apr 8, 2016 at 14:13
  • My bad, edited that to original post, thx. Commented Apr 8, 2016 at 14:23
  • This should be just ordinary startup script... Commented Apr 8, 2016 at 14:27

2 Answers 2

18

Here is another way

import robot

logFile = open('mylog.txt', 'w') 
robot.run("tmp.robot",stdout=logFile)
Sign up to request clarification or add additional context in comments.

1 Comment

this is the best answer! detailed instruction of usage can be found in robot.run.py
5

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'])

9 Comments

First one has same result as in main topic
@user2678074 What is the full path to the robot program and are you absolutely sure that D:/aaa/test/aaa.robot is correct?
Yes. I added specially print os.getcwd() and the path is correct. Double checked
sorry for that :) C:\Python27\Scripts\ride.py btw...it is added to the PATH
Great :) The only reason you can type robot in the terminal and run a program, is because your computer knows that robot actually means ` C:/Python27/Scripts/robot.bat. robot is an alias or a "custom" nickname for an actual program. These "nicknames" and user settings are called environment variables. They only apply to your user. From Python's perspective, robot makes no sense - it needs the full path to the executable or you need to explicitly set cwd= in the subproces command. Maybe this will work too: call(['robot.bat', 'D:/aaa/test/aaa.robot'], cwd='C:/Python27/Scripts')
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.