Exemple #1
0
def startDetached( cmd ):
  """Run a command in the background with psutil

  Parameters:
    * cmd (list): command to be executed with its arguments.

  Returns:
    psutil.Popen: Object view of the process

  Notes:
    * The command is executed by the Popen function of the psutil module.
    * Since the command is run as a daemon, it does not block the execution of the script.
    * stdout is captured and forwarded to odpy.proclog_logger.
    * stderr is captured and forwarded to odpy.syslog_logger.

  """

  try:
    if isWin():
      runningproc = psutil.Popen( cmd, stdout=get_log_stream(), \
                                       stderr=get_std_stream() )
    else:
      runningproc = psutil.Popen( cmd, start_new_session=True, \
                                     stdout=get_log_stream(), \
                                     stderr=get_std_stream() )
  except subprocess.CalledProcessError as err:
    std_msg( 'Failed: ', err )
    raise
  return runningproc
Exemple #2
0
def startDetached( cmd ):
 try:
   if isWin():
     runningproc = psutil.Popen( cmd, stdout=get_log_stream(), \
                                      stderr=get_std_stream() )
   else:
     runningproc = psutil.Popen( cmd, start_new_session=True, \
                                     stdout=get_log_stream(), \
                                     stderr=get_std_stream() )
 except subprocess.CalledProcessError as err:
   std_msg( 'Failed: ', err )
   raise
 return runningproc
Exemple #3
0
def startDetached(cmd):
    try:
        if isWin():
            runningproc = psutil.Popen( cmd, stdout=get_log_stream(), \
                                             stderr=get_std_stream() )
        else:
            runningproc = psutil.Popen( cmd, start_new_session=True, \
                                            stdout=get_log_stream(), \
                                            stderr=get_std_stream() )
    except subprocess.CalledProcessError as err:
        std_msg('Failed: ', err)
        raise
    return runningproc
Exemple #4
0
def startAndWait( cmd ):
  try:
    completedproc = subprocess.run( cmd, check=True, stdout=subprocess.PIPE, \
                                    stderr=get_std_stream() ).stdout
  except subprocess.CalledProcessError as err:
    std_msg( 'Failed: ', err )
    raise
  return completedproc
Exemple #5
0
def startAndWait(cmd):
    try:
        completedproc = subprocess.run( cmd, check=True, stdout=subprocess.PIPE, \
                                        stderr=get_std_stream() ).stdout
    except subprocess.CalledProcessError as err:
        std_msg('Failed: ', err)
        raise
    return completedproc
Exemple #6
0
def startAndWait(cmd):
    """Run a command with subprocess

  Parameters:
    * cmd (list): command to be executed with its arguments.

  Returns:
    * str:
      stdout from the executed and retrieved subprocess.CompletedProcess

  Notes:
    * The command is executed by the run function of the subprocess module.
    * stdout is captured with a PIPE from the child process.
    * stderr is captured and forwarded to odpy.syslog_logger.

  """

    try:
        completedproc = subprocess.run( cmd, check=True, stdout=subprocess.PIPE, \
                                        stderr=get_std_stream() ).stdout
    except subprocess.CalledProcessError as err:
        std_msg('Failed: ', err)
        raise
    return completedproc