本文整理匯總了Python中subprocess.CREATE_NEW_CONSOLE屬性的典型用法代碼示例。如果您正苦於以下問題:Python subprocess.CREATE_NEW_CONSOLE屬性的具體用法?Python subprocess.CREATE_NEW_CONSOLE怎麽用?Python subprocess.CREATE_NEW_CONSOLE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類subprocess
的用法示例。
在下文中一共展示了subprocess.CREATE_NEW_CONSOLE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def __init__(self, url, dest, progress_bar=False):
self.url = url
self.dest = dest
self.hash_type = None
self.hash_value = None
self.process = None
self.secret = ''.join(format(ord(x), 'x') for x in os.urandom(10))
self.gid = 'DEADC0D9BEEFFACE'
self.status = None
self.failed = False
self.failure = None
self.ariaStatus = {}
self.gid = None
if platform.system()=='Darwin':
self.aria_stdout = None
self.startupinfo = None
else:
self.aria_stdout = None
self.startupinfo = subprocess.STARTUPINFO()
self.startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
self.startupinfo.wShowWindow = subprocess.SW_HIDE
示例2: apply_cli_session
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def apply_cli_session(cls, creds, region):
''' Applies the given credentials (i.e. AccessKey, SecretAccessKey and SessionToken) to a new shell to use with aws cli.
The credentials are used as environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AWS_DEFAULT_REGION
that aws cli uses.
The region is the desired region to connect to (e.g. us-east-1).
:param : boto3 returned credentials dict
:param region: aws region to connect to
'''
# Set up environment for opening shell with credentials
os.environ["AWS_ACCESS_KEY_ID"] = creds["AccessKeyId"]
os.environ["AWS_SECRET_ACCESS_KEY"] = creds["SecretAccessKey"]
os.environ["AWS_SESSION_TOKEN"] = creds["SessionToken"]
os.environ["AWS_DEFAULT_REGION"] = region
# Open up a new shell
if os.name == 'nt':
subprocess.Popen(r"cmd", creationflags=subprocess.CREATE_NEW_CONSOLE)
else:
os.system(os.environ['SHELL'])
示例3: runScript
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def runScript(cls, script, version=None, architecture=64, language=ScriptLanguage.Python, debug=False, headless=True):
# If the script argument is a path to a file.
if os.path.exists(script):
with open(script, 'r') as fle:
script = fle.read()
scriptPath = os.path.splitext(cls.scriptPath())[0] + '.py'
with open(scriptPath, 'w') as fle:
fle.write(script)
binary = os.path.join(cls.binariesPath(version, architecture), 'mayabatch.exe' if headless else 'maya.exe')
args = [binary, '-console', '-verbosePython', scriptPath]
subprocess.Popen(args, creationflags=subprocess.CREATE_NEW_CONSOLE, env=os.environ)
# TODO: Need to figure out a way to return False if the script has failed.
return True
示例4: runScript
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def runScript(cls, script, version=None, architecture=64, language=ScriptLanguage.Python, debug=False, headless=True):
if os.path.exists(script):
scriptPath = script
else:
scriptPath = cls.scriptPath()
with open(scriptPath, "w") as fle:
fle.write(script)
if language == ScriptLanguage.Python:
scriptTemplate = os.path.join(os.path.dirname(__file__), 'templates', 'external_python_script.mstempl')
with open(scriptTemplate) as fle:
script = fle.read().format(scriptPath =scriptPath, debug=debug)
scriptPath = os.path.splitext(cls.scriptPath())[0] + '.ms'
with open(scriptPath, "w") as fle:
fle.write(script)
binary = os.path.join(cls.binariesPath(version, architecture), '3dsmax.exe')
process = subprocess.Popen([binary, '-U', 'MAXScript', scriptPath], creationflags=subprocess.CREATE_NEW_CONSOLE, env=os.environ)
# TODO: Need to figure out a way to return False if the script has failed.
return True
示例5: write_windows_console
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def write_windows_console(self, *args):
retcode = subprocess.call(args,
# use a new console to not flood the test output
creationflags=subprocess.CREATE_NEW_CONSOLE,
# use a shell to hide the console window (SW_HIDE)
shell=True)
self.assertEqual(retcode, 0)
示例6: __enter__
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def __enter__(self):
"""Entering the `with` block. Runs the process."""
if not self._kernel32.CreateProcessA(
None, # lpApplicationName
self.command_str, # lpCommandLine
None, # lpProcessAttributes
None, # lpThreadAttributes
False, # bInheritHandles
subprocess.CREATE_NEW_CONSOLE, # dwCreationFlags
None, # lpEnvironment
str(PROJECT_ROOT).encode('ascii'), # lpCurrentDirectory
ctypes.byref(self.startup_info), # lpStartupInfo
ctypes.byref(self.process_info) # lpProcessInformation
):
raise ctypes.WinError()
# Add handles added by the OS.
self._handles.append(self.process_info.hProcess)
self._handles.append(self.process_info.hThread)
# Get hWnd.
self.hwnd = 0
for _ in range(int(5 / 0.1)):
# Takes time for console window to initialize.
self.hwnd = ctypes.windll.user32.FindWindowA(None, self.startup_info.lpTitle)
if self.hwnd:
break
time.sleep(0.1)
assert self.hwnd
# Return generator that yields window size/position.
return self._iter_pos()
示例7: spawn_local
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def spawn_local(self, idx):
"""
This method launches processes that are needed to run on this computer
:param idx: An index into launch_db
"""
# get the launch entry in launch_db
db_entry = self.launch_db[idx]
# skip over the entry for the backplane
# launch the process either in its own window or just launch it.
# differentiate between windows and other os's.
if not db_entry['command_string'] == 'backplane':
if sys.platform.startswith('win32'):
if db_entry['spawn'] == 'yes':
self.proc = Popen(db_entry['command_string'],
creationflags=subprocess.CREATE_NEW_CONSOLE)
else:
command_list = db_entry['command_string']
self.proc = Popen(command_list, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
else:
if db_entry['spawn'] == 'yes':
self.proc = Popen(['xterm', '-e', db_entry['command_string']],
stdin=subprocess.PIPE, stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
else:
command_list = db_entry['command_string'].split(' ')
self.proc = Popen(command_list)
# update the entry with the launch information
db_entry['process'] = self.proc
db_entry['process_id'] = self.proc.pid
print('{:35} PID = {}'.format(db_entry['command_string'], str(self.proc.pid)))
# allow a little time for the process to startup
try:
time.sleep(0.5)
except (KeyboardInterrupt, SystemExit):
self.clean_up()
示例8: start_server
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def start_server(self):
if self.android is None:
if self.enabled and self.lang.voice is not None:
cmd = ['espeak']
cmd.extend(self.lang.voice)
try:
# IS_WIN32 = 'win32' in str(sys.platform).lower() #maybe sys.platform is more secure
is_win = platform.system() == "Windows"
if is_win:
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
kwargs = {}
kwargs['startupinfo'] = startupinfo
self.process = subprocess.Popen(cmd, shell=False, bufsize=0, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
startupinfo=startupinfo)
else:
if self.debug:
self.process = subprocess.Popen(cmd, shell=False, bufsize=0, stdin=subprocess.PIPE)
else:
self.process = subprocess.Popen(cmd, shell=False, bufsize=0, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self.started = True
except:
self.enabled = False
self.started = False
print("eduActiv8: You may like to install eSpeak to get some extra functionality, " +
"however this is not required to successfully use the game.")
else:
self.process = None
示例9: run
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def run(self):
'''
Spawn the process that will run the vivado process.
'''
cwd = os.getcwd()
os.chdir(self.directory)
stdout_fn = 'stdout.txt'
stderr_fn = 'stderr.txt'
command_fn = 'command.tcl'
if os.name == 'nt':
commands = [config.vivado, '-log', stdout_fn, '-mode', 'batch',
'-source', command_fn]
logger.debug('running vivado task in directory {}'.format(self.directory))
logger.debug('command is {}'.format(' '.join(commands)))
self.process = subprocess.Popen(
commands,
# So that process stays alive when terminal is closed
# in Windows.
# Commented out because doesn't seem to be working now.
creationflags=subprocess.CREATE_NEW_CONSOLE,
)
logger.debug('started process')
else:
commands = [config.vivado, '-mode', 'batch', '-source',
command_fn]
self.launch_unix_subprocess(
commands, stdout_fn=stdout_fn, stderr_fn=stderr_fn)
os.chdir(cwd)
示例10: update
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def update():
'''
Updates ExtAnalysis
1. Create the updater child script and save it to temp directory
2. End self process and start the child script
'''
print("\n[i] Creating Updater file")
child_script = open(helper.fixpath(core.path + '/db/updater.py'), 'r')
child_script = child_script.read()
src = child_script.replace('<current_extanalysis_directory>', core.path.replace('\\', '\\\\'))
src = src.replace('<github_zip_url>', core.github_zip)
print('[i] Moving updater file to temp directory')
temp_dir = tempfile.gettempdir()
updater_script = helper.fixpath(temp_dir + '/update_extanalysis.py')
f = open(updater_script, 'w+')
f.write(src)
f.close()
python_loc = sys.executable
print('[i] Starting Updater script')
if sys.platform == 'win32':
os.chdir(temp_dir)
command = [python_loc, 'update_extanalysis.py']
subprocess.Popen(command, creationflags=subprocess.CREATE_NEW_CONSOLE, shell=False)
print('[i] Killing self... Next time we meet I will be a better version of myself ;)')
exit()
else:
os.chdir(temp_dir)
command = ['x-terminal-emulator', '-e', python_loc, updater_script]
subprocess.Popen(command, shell=False)
print('[i] Killing self... Next time we meet I will be a better version of myself ;)')
exit()
示例11: _fork_worker
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def _fork_worker(namespace_path, child_env, pid_file, invocation, chdir,
stdin_goto, stdout_goto, stderr_goto, _exit_caller, args):
''' Opens a fork worker, shielding the parent from cancellation via
signal sending. Basically, thanks Windows for being a dick about
signals.
'''
# Find out our PID so the daughter can tell us to exit
my_pid = os.getpid()
# Pack up all of the args that the child will need to use.
# Prepend it to *args
payload = (my_pid, pid_file, chdir, stdin_goto, stdout_goto,
stderr_goto, _exit_caller) + args
# Pack it up. We're shielded from pickling errors already because pickle is
# needed to start the worker.
# Write the payload to the namespace passer using the highest available
# protocol
with open(namespace_path, 'wb') as f:
pickle.dump(payload, f, protocol=-1)
# Invoke the invocation!
daemon = subprocess.Popen(
invocation,
# This is important, because the parent _forkish is telling the child
# to run as a daemon via env. Also note that we need to calculate this
# in the root _daemonize1, or else we'll have a polluted environment
# due to the '__CREATE_DAEMON__' key.
env = child_env,
# This is vital; without it, our process will be reaped at parent
# exit.
creationflags = subprocess.CREATE_NEW_CONSOLE,
)
# Busy wait until either the daemon exits, or it sends a signal to kill us.
daemon.wait()
示例12: launch
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def launch(fn, prefix=config.root_dir, additional_args=None, background=False):
info = install.is_linked(prefix, fn[:-8])
if info is None:
return None
if not info.get('type') == 'app':
raise TypeError('Not an application: %s' % fn)
binpath, env = environment_for_conda_environment(prefix)
# allow updating environment variables from metadata
if 'app_env' in info:
env.update(info['app_env'])
# call the entry command
args = info['app_entry'].split()
args = [a.replace('${PREFIX}', prefix) for a in args]
arg0 = find_executable(args[0], env['PATH'])
if arg0 is None:
raise Exception('Executable not found: %s' % args[0])
args[0] = arg0
cwd = abspath(expanduser('~'))
if additional_args:
args.extend(additional_args)
if sys.platform == 'win32' and background:
return subprocess.Popen(args, cwd=cwd, env=env, close_fds=False,
creationflags=subprocess.CREATE_NEW_CONSOLE)
else:
return subprocess.Popen(args, cwd=cwd, env=env, close_fds=False)
示例13: execute_in_environment
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def execute_in_environment(cmd, prefix=config.root_dir, additional_args=None,
inherit=True):
"""Runs ``cmd`` in the specified environment.
``inherit`` specifies whether the child inherits stdio handles (for JSON
output, we don't want to trample this process's stdout).
"""
binpath, env = environment_for_conda_environment(prefix)
if sys.platform == 'win32' and cmd == 'python':
# python is located one directory up on Windows
cmd = join(binpath, '..', cmd)
args = shlex.split(cmd)
if additional_args:
args.extend(additional_args)
if inherit:
stdin, stdout, stderr = None, None, None
else:
stdin, stdout, stderr = subprocess.PIPE, subprocess.PIPE, subprocess.PIPE
if sys.platform == 'win32' and not inherit:
return subprocess.Popen(args, env=env, close_fds=False,
stdin=stdin, stdout=stdout, stderr=stderr,
creationflags=subprocess.CREATE_NEW_CONSOLE)
else:
return subprocess.Popen(args, env=env, close_fds=False,
stdin=stdin, stdout=stdout, stderr=stderr)
示例14: DeamonHelper
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def DeamonHelper(inName, argLen, scriptName, fileHead):
inName = os.path.join(customDownDir, inName + '.txt')
lines = SafeReadandWriteHead(inName, fileHead)
if len(lines):
inf = codecs.open(inName, 'w+', 'utf-8')
if fileHead:
fileHead = [l.strip() + '\n' for l in fileHead]
inf.writelines(fileHead)
else:
inf.write('')
inf.close()
while lines:
args = GrabArgs(lines, argLen)
lines = lines[len(args):]
print(inName + ' command: ' + time.ctime())
for arg in args:
print(arg)
# For safety
time.sleep(0.5)
subprocess.Popen(
[
'py', '-3', os.path.join(scriptDir, scriptName + '.py')
] + args,
creationflags = subprocess.CREATE_NEW_CONSOLE
)
示例15: _execute_tool
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import CREATE_NEW_CONSOLE [as 別名]
def _execute_tool(self, qaction):
if qaction:
_tools = self.prefs.get('tools')
if _tools:
for _tool in _tools:
if _tool and _tool['name'] and _tool['name'] != 'sep':
if qaction.text() == _tool['name']:
try:
import subprocess
subprocess.Popen(_tool['cmd'], creationflags=subprocess.CREATE_NEW_CONSOLE)
except:
pass
break