Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #30 from tradebyte/fix-issue-subprocess-bash
Browse files Browse the repository at this point in the history
Fix issue subprocess bash
  • Loading branch information
bahador-farahani-tradebyte authored May 18, 2021
2 parents 5291c35 + 1d64a05 commit 38757ed
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Help:

## Limitations

* It currently targets Ubuntu 16.04 only!
* It currently targets Ubuntu only!
* It needs more packages.
* It needs testing.
* It only supports 64bit systems.
Expand Down
2 changes: 1 addition & 1 deletion paci/helpers/cmd_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def execute_shell_script(script, working_dir):
"""Execute a shell script."""
st = os.stat(script)
os.chmod(script, st.st_mode | stat.S_IEXEC)
subprocess.call(script, shell=False, cwd=working_dir)
subprocess.call(script, shell=True, cwd=working_dir)


def set_script_variables(values):
Expand Down
13 changes: 3 additions & 10 deletions paci/packages/cli_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def debug_execute(cmd, cwd=None):
popen = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
universal_newlines=True,
shell=False,
shell=True,
cwd=cwd)
for stdout_line in iter(popen.stdout.readline, ""):
yield stdout_line
Expand All @@ -56,25 +56,18 @@ def sh(cmd, cwd=None):
True if the execution was successful but no output was given.
The output of the command if it was successful and stdout wasn't empty.
"""
# We want to interpolate env variables before executing the command, because shell=False
# cannot handle these. Using shell=True is no option since it is a security risk.
if isinstance(cmd, list):
cmd_list = cmd
else:
cmd_list = cmd.split()
cmd_list = list(map(lambda x: os.path.expandvars(x), cmd_list))

if DEBUG:
stdout = ""
for path in debug_execute(cmd_list, cwd=cwd):
for path in debug_execute(cmd, cwd=cwd):
print(path, end="")
stdout += path
if stdout:
return stdout.rstrip()
else:
return False
else:
executed_cmd = Shell(cmd_list, cwd=cwd)
executed_cmd = Shell(cmd, cwd=cwd)
if executed_cmd.code == 0:
if executed_cmd.stdout:
return str(executed_cmd)
Expand Down
10 changes: 1 addition & 9 deletions paci/packages/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,8 @@ def __init__(self, *args, **kwargs):
self.bash(*args, **kwargs)

def bash(self, cmd, env=None, stdout=PIPE, stderr=PIPE, timeout=None, sync=True, cwd=None):
# We want to interpolate env variables before executing the command, because shell=False
# cannot handle these. Using shell=True is no option since it is a security risk.
if isinstance(cmd, list):
cmd_list = cmd
else:
cmd_list = cmd.split()
cmd_list = list(map(lambda x: os.path.expandvars(x), cmd_list))

self.p = Popen(
cmd_list, shell=False, stdout=stdout, stdin=PIPE, stderr=stderr, env=env, cwd=cwd
cmd, shell=True, stdout=stdout, stdin=PIPE, stderr=stderr, env=env, cwd=cwd
)
if sync:
self.sync(timeout)
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tinydb==3.2.2
tabulate==0.7.7
fuzzywuzzy==0.15.0
python-Levenshtein==0.12.0
halo==0.0.7
halo==0.0.31
termcolor==1.1.0
easydict==1.7
log_symbols==0.0.12
log_symbols==0.0.14

0 comments on commit 38757ed

Please sign in to comment.