-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcmd_commands.py
More file actions
31 lines (25 loc) · 1002 Bytes
/
Copy pathcmd_commands.py
File metadata and controls
31 lines (25 loc) · 1002 Bytes
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
from logicytics import log, execute
@log.function
def command(file: str, commands: str, message: str, encoding: str = "UTF-8") -> None:
"""
Executes a command and writes the output to a file.
Args:
file (str): The name of the file to write the command output to.
commands (str): The command to be executed.
message (str): A message to be logged.
encoding (str): The encoding to write the file in.
Returns:
None
"""
log.info(f"Executing {message}")
try:
output = execute.command(commands)
with open(file, "w", encoding=encoding) as f:
f.write(output)
log.info(f"{message} Successful - {file}")
except Exception as e:
log.error(f"Error while getting {message}: {e}")
if __name__ == "__main__":
command("Drivers.txt", "driverquery /v", "Driver Query")
command("SysInfo.txt", "systeminfo", "System Info")
command("GPResult.txt", "GPResult /r", "GPResult", "windows-1252")