#####################################
# Command code
####################################
import shlex
import subprocess
class CommandError(Exception):
pass
class Command(object):
"""
Class to simplify the process of running a command and getting the output
and return code
"""
def __init__(self, command=None):
self.command = command
self.args = None
self.subprocess = None
self.output = None
self.errors = None
self.status = None
self.result = None
def run(self, command=None):
if command is not None:
self.command = command
if self.command is None:
raise CommandError('No command specified')
self.args = shlex.split(self.command)
self.subprocess = subprocess.Popen(self.args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.output, self.errors = self.subprocess.communicate()
self.subprocess.wait(60)
self.status = self.subprocess.returncode
self.result = (0 == self.status)
return self.result
def A(X, logger,device_name,ip_address,value_type, value):
command_string = "my_command"
cmd = Command(command_string)
time.sleep(1.0)
if not cmd.run():
logger.error("cmd.errors = %s", device_name, cmd.errors.rstrip())
elif 'No Such Instance' in cmd.output:
logger.error("cmd.output = %s", device_name, cmd.output.rstrip())
else:
result = True
return result
I added a self.subprocess.wait(60) for 60 seconds for my commands to run with a timeout value specified.
But it is throwing the following error ::self.subprocess.wait(60) TypeError: wait() takes exactly 1 argument (2 given)
What is the problem with the code? Can anyone point out the issue?