Esempio n. 1
0
def spawn_job_bg(command,
                 stdin=DEV_NULL,
                 stdout=DEV_NULL,
                 stderr=DEV_NULL,
                 fd_except=None,
                 cwd=None,
                 env=None,
                 pgrp=0):
    """Spawn a job into the background.

    :Parameters:
        - `command`: The command to execute.  If it is a string, it will be
          parsed for command-line arguments.  Otherwise it assumes it is a
          sequence of arguments, with the first element being the command to
          execute.

          If the command does not contain a slash (/) it will search the PATH
          environment for the executable.
        - `stdin`: Either `DEV_NULL` or `PIPE`.
        - `stdout`: Either `DEV_NULL` or `PIPE`.
        - `stderr`: Either `DEV_NULL`, `PIPE`, or `STDOUT`.
        - `fd_except`: A list of file descriptors to NOT close.  By default all
          file descriptors (except for stdin/stdout/stderr are closed).
        - `cwd`: The working directory to use for the child process (the
          default is to leave it alone).
        - `env`: The environment to use.  If None, the environment is not
          changed.  May be a dictionary or a list of 'NAME=VALUE' strings.
        - `pgrp`: Set to -1 to keep process group unchanged, 0 to create a new
          job (default) and >0 to set process group to pgrp

    :Return:
        Returns a `CoroProcess` instance.

    :Exceptions:
        - `OSError`: General low-level error.
        - `ValueError`: The command value is invalid.
    """
    pid, in_fd, out_fd, err_fd = _process.spawn_job_bg(command, stdin, stdout,
                                                       stderr, fd_except, cwd,
                                                       env, pgrp)
    if in_fd != -1:
        in_file = coro.fd_sock(in_fd)
    else:
        in_file = None
    if out_fd != -1:
        out_file = coro.fd_sock(out_fd)
    else:
        out_file = None
    if err_fd == out_fd:
        err_file = out_file
    elif err_fd != -1:
        err_file = coro.fd_sock(err_fd)
    else:
        err_file = None

    return CoroProcess(command, pid, in_file, out_file, err_file)
Esempio n. 2
0
def spawn_job_bg(command, stdin=DEV_NULL, stdout=DEV_NULL, stderr=DEV_NULL, fd_except=None, cwd=None, env=None, pgrp=0):
    """Spawn a job into the background.

    :Parameters:
        - `command`: The command to execute.  If it is a string, it will be
          parsed for command-line arguments.  Otherwise it assumes it is a
          sequence of arguments, with the first element being the command to
          execute.

          If the command does not contain a slash (/) it will search the PATH
          environment for the executable.
        - `stdin`: Either `DEV_NULL` or `PIPE`.
        - `stdout`: Either `DEV_NULL` or `PIPE`.
        - `stderr`: Either `DEV_NULL`, `PIPE`, or `STDOUT`.
        - `fd_except`: A list of file descriptors to NOT close.  By default all
          file descriptors (except for stdin/stdout/stderr are closed).
        - `cwd`: The working directory to use for the child process (the
          default is to leave it alone).
        - `env`: The environment to use.  If None, the environment is not
          changed.  May be a dictionary or a list of 'NAME=VALUE' strings.
        - `pgrp`: Set to -1 to keep process group unchanged, 0 to create a new
          job (default) and >0 to set process group to pgrp

    :Return:
        Returns a `CoroProcess` instance.

    :Exceptions:
        - `OSError`: General low-level error.
        - `ValueError`: The command value is invalid.
    """
    pid, in_fd, out_fd, err_fd = _process.spawn_job_bg(command, stdin, stdout, stderr, fd_except, cwd, env, pgrp)
    if in_fd != -1:
        in_file = coro.fd_sock(in_fd)
    else:
        in_file = None
    if out_fd != -1:
        out_file = coro.fd_sock(out_fd)
    else:
        out_file = None
    if err_fd == out_fd:
        err_file = out_file
    elif err_fd != -1:
        err_file = coro.fd_sock(err_fd)
    else:
        err_file = None

    return CoroProcess(command, pid, in_file, out_file, err_file)
Esempio n. 3
0
def transport_thread(channel):
    stdout = coro.fd_sock (1)
    while not channel.eof and not channel.closed:
        try:
            data = channel.read(1024)
            if data:
                stdout.send (data)
                #os.write(1, data)
        except EOFError:
            break
    coro.set_exit()
Esempio n. 4
0
def transport_thread(channel):
    stdout = coro.fd_sock(1)
    while not channel.eof and not channel.closed:
        try:
            data = channel.read(1024)
            if data:
                stdout.send(data)
                # os.write(1, data)
        except EOFError:
            break
    coro.set_exit()
Esempio n. 5
0
def input_thread(channel):
    stdin = coro.fd_sock(0)
    while 1:
        data = stdin.recv(100)
        channel.send(data)
Esempio n. 6
0
def input_thread(channel):
    stdin = coro.fd_sock(0)
    while 1:
        data = stdin.recv(100)
        channel.send(data)