forked from trustedsec/ptf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.py
38 lines (32 loc) · 1.24 KB
/
commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
##########################
# After commands module
##########################
import subprocess
import os
from src.core import *
# this will execute after everything is over
def after_commands(command, install_location):
# if there is more than one command iterate through
if "," in command:
# get current working directory
definepath = os.getcwd()
original_command = command
command = command.split(",")
# iterate through commands
for commands in command:
print_status("Sending after command: " + commands)
# change directory if CD in command
if "cd " in commands:
cwd = os.getcwd()
commands = commands.replace("cd ", "")
if os.path.isdir(commands):
os.chdir(commands)
else:
# this is commented out for now because for some reason it removes stdout for prompts
#subprocess.Popen(commands, stderr=subprocess.PIPE, shell=True).wait()
subprocess.Popen(commands, shell=True).wait()
# restore original directory
os.chdir(definepath)
else:
subprocess.Popen(command, shell=True).wait()