summaryrefslogtreecommitdiff
path: root/bin/tools
diff options
context:
space:
mode:
authorP. Christeas <p_christ@hol.gr>2010-11-23 17:22:24 +0200
committerP. Christeas <p_christ@hol.gr>2010-11-23 17:22:24 +0200
commitd4379792fc53002b51f54b8a105ff420f4e4bef4 (patch)
treee5cbb54f64fe9345df66979854d0bb4baaa21807 /bin/tools
parentb4e5c513112036bb6d6eee7e16eda547ccda80eb (diff)
tools/misc: port the exec_command_pipe() to the subprocess module.
The os.popen2 is deprecated since Python 2.6. It also failed to properly escape the command line arguments. Conflicts: bin/tools/misc.py bzr revid: p_christ@hol.gr-20101123152224-d52414w2tscw6bvo
Diffstat (limited to 'bin/tools')
-rw-r--r--bin/tools/misc.py20
1 files changed, 9 insertions, 11 deletions
diff --git a/bin/tools/misc.py b/bin/tools/misc.py
index 79121eb89c9..381ffb9677f 100644
--- a/bin/tools/misc.py
+++ b/bin/tools/misc.py
@@ -25,6 +25,7 @@ Miscelleanous tools used by OpenERP.
"""
import inspect
+import subprocess
import logging
import os
import re
@@ -141,27 +142,24 @@ def exec_pg_command(name, *args):
if not prog:
raise Exception('Couldn\'t find %s' % name)
args2 = (os.path.basename(prog),) + args
- return os.spawnv(os.P_WAIT, prog, args2)
+
+ return subprocess.call(args2, executable=prog)
def exec_pg_command_pipe(name, *args):
prog = find_pg_tool(name)
if not prog:
raise Exception('Couldn\'t find %s' % name)
- if os.name == "nt":
- cmd = '"' + prog + '" ' + ' '.join(args)
- else:
- cmd = prog + ' ' + ' '.join(args)
- return os.popen2(cmd, 'b')
+ pop = subprocess.Popen(args, executable=prog, shell=True, bufsize= -1,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
+ return (pop.stdin, pop.stdout)
def exec_command_pipe(name, *args):
prog = find_in_path(name)
if not prog:
raise Exception('Couldn\'t find %s' % name)
- if os.name == "nt":
- cmd = '"'+prog+'" '+' '.join(args)
- else:
- cmd = prog+' '+' '.join(args)
- return os.popen2(cmd, 'b')
+ pop = subprocess.Popen(args, executable=prog, shell=True, bufsize= -1,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
+ return (pop.stdin, pop.stdout)
#----------------------------------------------------------
# File paths