Last active
August 29, 2015 14:02
-
-
Save drgarcia1986/9a4f3552acc5241eaafa to your computer and use it in GitHub Desktop.
[python-brasil] carregar processo independente
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import os | |
>>> programa = r'C:\Program Files (x86)\mongoDB\bin\mongod.exe' | |
>>> parametros = r'--logpath "C:\Foo\Bar\Base\install.log" --dbpath "C:\Foo\Bar\Base\data\db" --port 1124' | |
>>> os.path.dirname(programa) | |
'C:\\Program Files (x86)\\mongoDB\\bin' | |
>>> os.path.basename(programa) | |
'mongod.exe' | |
>>> os.spawnl(os.P_WAIT, os.path.dirname(programa), os.path.basename(programa), parametros) | |
Traceback (most recent call last): | |
File "<pyshell#20>", line 1, in <module> | |
os.spawnl(os.P_WAIT, os.path.dirname(programa), os.path.basename(programa), parametros) | |
File "C:\Python33\lib\os.py", line 922, in spawnl | |
return spawnv(mode, file, args) | |
FileNotFoundError: [Errno 2] No such file or directory | |
>>> os.spawnl(os.P_WAIT, "%s %s".format(programa, parametros)) | |
#aqui ocorre crash no pythonw |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import platform | |
import subprocess | |
def carregar_processo(cmd): | |
if platform.system() == "Windows": | |
DETACHED_PROCESS = 0x00000008 | |
CREATE_NEW_PROCESS_GROUP = 0x00000200 | |
return subprocess.Popen(cmd, creationflags=DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP).pid | |
else: | |
return subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).pid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment