Run a daemon script command.

def exec_notebook_daemon_command(self, name, cmd, port=0):
        """Run a daemon script command."""
        cmd = self.get_notebook_daemon_command(name, cmd, port)

        # Make all arguments explicit strings
        cmd = [str(arg) for arg in cmd]

        logger.info("Running notebook command: %s", " ".join(cmd))
        # print("XXX - DEBUG - Running notebook command:", " ".join(cmd))

        # Add support for traceback dump on stuck
        env = os.environ.copy()
        env["PYTHONFAULTHANDLER"] = "true"

        p = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, env=env)
        time.sleep(0.2)
        stdout, stderr = p.communicate()

        if b"already running" in stderr:
            raise RuntimeError("Looks like notebook_daemon is already running. Please kill it manually pkill -f notebook_daemon. Was: {}".format(stderr.decode("utf-8")))

        if p.returncode != 0:
            logger.error("STDOUT: %s", stdout)
            logger.error("STDERR: %s", stderr)

            raise RuntimeError("Could not execute notebook command. Exit code: {} cmd: {}".format(p.returncode, " ".join(cmd)))

        return stdout