Esempio n. 1
0
def shell_entry_point(args: List[str]):
    program = args[0]
    path = find_in_path(program)
    remaining_args = args[1:]
    command = " ".join(args)
    environment = get_environment()

    subprocess.run(args)
    subprocess.check_call(args)
    subprocess.check_output(args)

    subprocess.Popen(args)

    subprocess.getstatusoutput(command)
    subprocess.getoutput(command)

    asyncio.subprocess.create_subprocess_exec(program, remaining_args)
    asyncio.subprocess.create_subprocess_shell(command)

    # TODO
    loop = asyncio.get_event_loop()
    loop.subprocess_exec(get_protocol_factory(), args)
    loop.subprocess_shell(get_protocol_factory(), command)

    os.execl(path, *remaining_args)
    os.execle(path, *remaining_args, environment)
    os.execlp(program, *remaining_args)
    os.execlpe(program, *remaining_args, environment)
    os.execv(path, remaining_args)
    os.execve(path, remaining_args, environment)
    os.execvp(program, remaining_args)
    os.execvpe(program, remaining_args, environment)

    os.popen(command)

    # TODO
    os.posix_spawnp(path, remaining_args, environment)
    os.posix_spawn(path, remaining_args, environment)

    os.spawnl(os.P_WAIT, path, *remaining_args)
    os.spawnle(os.P_WAIT, path, *remaining_args, environment)
    os.spawnlp(os.P_WAIT, program, *remaining_args)
    os.spawnlpe(os.P_WAIT, program, *remaining_args, environment)
    os.spawnv(os.P_WAIT, path, remaining_args)
    os.spawnve(os.P_WAIT, path, remaining_args, environment)
    os.spawnvp(os.P_WAIT, program, remaining_args)
    # TODO
    os.spawnvpe(os.P_WAIT, program, remaining_args, environment)

    os.system(command)
def main():
    env = os.environ.copy()
    pythonpath = env.get('PYTHONPATH', '')
    env['PYTHONPATH'] = os.path.dirname(__file__) + os.pathsep + \
        os.path.dirname(os.path.dirname(os.path.dirname(__file__)))

    from _pydevd_bundle.pydevd_constants import HTTP_JSON_PROTOCOL
    from _pydevd_bundle.pydevd_defaults import PydevdCustomization
    PydevdCustomization.DEFAULT_PROTOCOL = HTTP_JSON_PROTOCOL

    import pydevd
    from _pydev_bundle import pydev_log
    pydev_log.debug('Argv received: %s', sys.argv)
    port = int(sys.argv[1])
    print('before pydevd.settrace')
    pydevd.settrace(port=port, patch_multiprocessing=True, suspend=True)
    print('after pydevd.settrace')

    import subprocess
    if '--use-c-switch' in sys.argv:
        child_process = subprocess.Popen(
            [
                sys.executable, '-u', '-c',
                'import _debugger_case_pydevd_customization;_debugger_case_pydevd_customization.call()'
            ],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            env=env,
        )
    elif '--posix-spawn' in sys.argv:
        env = os.environ.copy()
        args = [
            '-u', '_debugger_case_pydevd_customization.py', '--simple-call'
        ]
        pid = os.posix_spawn(sys.executable, args, env)
        os.waitpid(pid, 0)
        child_process = None  # We don't really have a subprocess.Popen instance in this case.
    else:
        child_process = subprocess.Popen(
            [
                sys.executable, '-u', '_debugger_case_pydevd_customization.py',
                '--simple-call'
            ],
            cwd=os.path.dirname(__file__),
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            env=env,
        )

    if child_process:
        stdout, stderr = child_process.communicate()
        assert b'called' in stdout, 'Did not find b"called" in stdout:\n>>%s<<\nstderr:\n>>%s<<\n' % (
            stdout, stderr)
    print('TEST SUCEEDED!')  # break 2 here
Esempio n. 3
0
def spawn_daemon(path_to_executable, *args, env=None):
    """Spawns a completely detached subprocess (i.e., a daemon).  Taken from
    http://stackoverflow.com/questions/972362/spawning-process-from-python
    which in turn was inspired by
    <http://code.activestate.com/recipes/278731/>.

    :Parameters:
      - `path_to_executable`: absolute path to the executable to be run
        detached
      - `args`: all arguments to be passed to the subprocess
      - `env`: if not None, the environment variables passed to the process;
        they are added to the ones of the current process, overriding in case
        of collisions

    :type path_to_executable: str
    :type args: list of str
    :type env: dict mapping str to str, or NoneType
    """
    env_ = os.environ.copy()
    if env is not None:
        env_.update(env)
    os.posix_spawn(path_to_executable, [path_to_executable] + list(args), env_)
 def run_payload(shell_command: str) -> None:
     args = shlex.split(shell_command)
     path = args[0]
     pid = os.posix_spawn(path, args, os.environ)
     os.waitpid(pid, 0)
           env)  # $getCommand="executable"
os.spawnlp(os.P_WAIT, "executable", "<progname>",
           "arg0")  # $getCommand="executable"
os.spawnlpe(os.P_WAIT, "executable", "<progname>", "arg0",
            env)  # $getCommand="executable"
os.spawnv(os.P_WAIT, "executable",
          ["<progname>", "arg0"])  # $getCommand="executable"
os.spawnve(os.P_WAIT, "executable", ["<progname>", "arg0"],
           env)  # $getCommand="executable"
os.spawnvp(os.P_WAIT, "executable",
           ["<progname>", "arg0"])  # $getCommand="executable"
os.spawnvpe(os.P_WAIT, "executable", ["<progname>", "arg0"],
            env)  # $getCommand="executable"

# Added in Python 3.8
os.posix_spawn("executable", ["<progname>", "arg0"],
               env)  # $getCommand="executable"
os.posix_spawnp("executable", ["<progname>", "arg0"],
                env)  # $getCommand="executable"

########################################

import subprocess

subprocess.Popen("cmd1; cmd2", shell=True)  # $getCommand="cmd1; cmd2"
subprocess.Popen("cmd1; cmd2",
                 shell="truthy string")  # $getCommand="cmd1; cmd2"
subprocess.Popen(["cmd1; cmd2", "shell-arg"],
                 shell=True)  # $getCommand="cmd1; cmd2"
subprocess.Popen(
    "cmd1; cmd2", shell=True,
    executable="/bin/bash")  # $getCommand="cmd1; cmd2" getCommand="/bin/bash"
Esempio n. 6
0
import os
import sys

pid = os.posix_spawn(sys.executable, [sys.executable, "test2.py"], os.environ)

pid, status = os.waitpid(pid, 0)
print(pid, status)
Esempio n. 7
0
os.spawnlpe(os.P_WAIT, "file", "<progname>", "arg0", env)  # $ getCommand="file" getAPathArgument="file"
os.spawnv(os.P_WAIT, "path", ["<progname>", "arg0"])  # $ getCommand="path" getAPathArgument="path"
os.spawnve(os.P_WAIT, "path", ["<progname>", "arg0"], env)  # $ getCommand="path" getAPathArgument="path"
os.spawnvp(os.P_WAIT, "file", ["<progname>", "arg0"])  # $ getCommand="file" getAPathArgument="file"
os.spawnvpe(os.P_WAIT, "file", ["<progname>", "arg0"], env)  # $ getCommand="file" getAPathArgument="file"

# unlike os.exec*, some os.spawn* functions is usable with keyword arguments. However,
# despite the docs using both `file` and `path` as the parameter name, you actually need
# to use `file` in all cases.
os.spawnv(mode=os.P_WAIT, file="path", args=["<progname>", "arg0"])  # $ getCommand="path" getAPathArgument="path"
os.spawnve(mode=os.P_WAIT, file="path", args=["<progname>", "arg0"], env=env)  # $ getCommand="path" getAPathArgument="path"
os.spawnvp(mode=os.P_WAIT, file="file", args=["<progname>", "arg0"])  # $ getCommand="file" getAPathArgument="file"
os.spawnvpe(mode=os.P_WAIT, file="file", args=["<progname>", "arg0"], env=env)  # $ getCommand="file" getAPathArgument="file"

# `posix_spawn` Added in Python 3.8
os.posix_spawn("path", ["<progname>", "arg0"], env)  # $ getCommand="path" getAPathArgument="path"
os.posix_spawn(path="path", argv=["<progname>", "arg0"], env=env)  # $ getCommand="path" getAPathArgument="path"

os.posix_spawnp("path", ["<progname>", "arg0"], env)  # $ getCommand="path" getAPathArgument="path"
os.posix_spawnp(path="path", argv=["<progname>", "arg0"], env=env)  # $ getCommand="path" getAPathArgument="path"

########################################

import subprocess

subprocess.Popen("cmd1; cmd2", shell=True)  # $getCommand="cmd1; cmd2"
subprocess.Popen("cmd1; cmd2", shell="truthy string")  # $getCommand="cmd1; cmd2"
subprocess.Popen(["cmd1; cmd2", "shell-arg"], shell=True)  # $getCommand="cmd1; cmd2"
subprocess.Popen("cmd1; cmd2", shell=True, executable="/bin/bash")  # $getCommand="cmd1; cmd2" getCommand="/bin/bash"

subprocess.Popen("executable")  # $getCommand="executable"