Merge pull request #993 from dolphincabal/shellCommands

Shell commands
php_fix
Chris Ross 2018-02-18 16:11:14 -05:00 committed by GitHub
commit 06ccf383ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 29 deletions

View File

@ -852,35 +852,8 @@ def data_webserver(data, ip, port, serveCount):
# additional implementation methods
def run_command(command):
if "|" in command:
command_parts = command.split('|')
elif ">" in command or ">>" in command or "<" in command or "<<" in command:
p = subprocess.Popen(command,stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
return ''.join(list(iter(p.stdout.readline, b'')))
elif ";" in command or "&&" in command:
p = subprocess.Popen(command,stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
return p.communicate()[0].strip()
else:
command_parts = []
command_parts.append(command)
i = 0
p = {}
for command_part in command_parts:
command_part = command_part.strip()
if i == 0:
p[i]=subprocess.Popen(shlex.split(command_part),stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
p[i]=subprocess.Popen(shlex.split(command_part),stdin=p[i-1].stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
i = i +1
(output, err) = p[i-1].communicate()
exit_code = p[0].wait()
if exit_code != 0:
errorStr = "Shell Output: " + str(output) + '\n'
errorStr += "Shell Error: " + str(err) + '\n'
return errorStr
else:
return str(output)
p = subprocess.Popen(command, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
return p.communicate()[0].strip()
def get_file_part(filePath, offset=0, chunkSize=512000, base64=True):