mirror of
https://github.com/nicolargo/glances.git
synced 2024-11-28 05:42:57 +03:00
Consider quotes when splitting command arguments
This commit is contained in:
parent
8bdbed3331
commit
848c0ef3ab
@ -11,6 +11,7 @@
|
||||
|
||||
from glances.compat import nativestr
|
||||
from subprocess import Popen, PIPE
|
||||
import re
|
||||
|
||||
|
||||
def secure_popen(cmd):
|
||||
@ -48,8 +49,8 @@ def __secure_popen(cmd):
|
||||
p_last = None
|
||||
# Split by pipe '|'
|
||||
for sub_cmd in cmd.split('|'):
|
||||
# Split by space ' '
|
||||
sub_cmd_split = [i for i in sub_cmd.split(' ') if i]
|
||||
# Split by space character, but do no split spaces within quotes
|
||||
sub_cmd_split = [_ for _ in list(filter(None, re.split(r'(\s+)|(".*?"+?)|(\'.*?\'+?)', sub_cmd))) if _ != ' ']
|
||||
p = Popen(sub_cmd_split, shell=False, stdin=sub_cmd_stdin, stdout=PIPE, stderr=PIPE)
|
||||
if p_last is not None:
|
||||
# Allow p_last to receive a SIGPIPE if p exits.
|
||||
|
Loading…
Reference in New Issue
Block a user