1

...using AutoKey 0.81.4 on Ubuntu 10.04

  1. relatively new to Linux (<1yr)
  2. This is the first python I've written

the following script for AutoKey keeps failing with the following error. What am I not getting here??

Script name: 'find files script'
Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/autokey/service.py", line 442, in execute
    exec script.code in self.scope
  File "<string>", line 13, in <module>
AttributeError: 'CalledProcessError' object has no attribute 'output'

The script

import time

time.sleep(0.10)
retCode, args =  dialog.input_dialog("Files to Find","enter a file name")
fmt = "find / -name \"{0}\" -type f -print 2>/dev/null "
if retCode == 0:
    if len(args) > 0:
        cmd = fmt.format(args)
        #dialog.info_dialog(title="the command",message=cmd)
        try:
            rc = system.exec_command(cmd, getOutput=True)
        except subprocess.CalledProcessError, e:
            dialog.info_dialog(title="the return",message=str(e.output))
Clare Macrae
  • 3,670
  • 2
  • 31
  • 45
kevcoder
  • 883
  • 1
  • 15
  • 29

2 Answers2

0

The output attribute doesn't exist until Python 2.6. You could use subprocess.Popen and communicate(). Or you could backport subprocess.check_output (also not in 2.6) following this.

orodbhen
  • 2,644
  • 3
  • 20
  • 29
-1

Change the e.output to just e. Using str(e) will get you the error string. You may want to look up exceptions to find out what attributes they support. I don't think output is one of them.

Demolishun
  • 1,592
  • 12
  • 15
  • 1
    This is incorrect. str(e) on a CalledProcessException gives: "Command '' returned non-zero exit status ". The [docs](http://docs.python.org/2/library/subprocess.html#subprocess.CalledProcessError.output) state that e.output should display the output of the child process. – Symmetric Aug 07 '13 at 17:14