Skip to content
Snippets Groups Projects
Commit 6006e041 authored by mads's avatar mads
Browse files

two step process execution (1:create process, 2: execute) now posible

parent 3ec14c9d
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ Created on 10/03/2014
'''
import os
import psutil
DEBUG = False
def pexec(args, cwd=None):
......@@ -28,3 +29,26 @@ def pexec(args, cwd=None):
errorcode = proc.returncode
return errorcode, stdout.decode(), stderr.decode(), cmd
def process(args, cwd=None):
import subprocess
if not isinstance(args, (list, tuple)):
args = [args]
args = [str(arg) for arg in args]
for i in range(len(args)):
if os.path.exists(args[i]):
args[i] = str(args[i]).replace('/', os.path.sep).replace('\\', os.path.sep).replace('"', '')
cmd = "%s" % '{} /c "{}"'.format (os.environ.get("COMSPEC", "cmd.exe"), subprocess.list2cmdline(args))
if cwd is not None and os.path.isfile(cwd):
cwd = os.path.dirname(cwd)
return subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, cwd=cwd)
def exec_process(process):
stdout, stderr = process.communicate()
errorcode = process.returncode
return errorcode, stdout.decode(), stderr.decode()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment