Detached PowerShell interactive session, but with full control
Project description
rlogfi provides a way to interact with PowerShell subprocesses in a detached and asynchronous manner
pip install rlogfi
Tested against Windows 10 / Python 3.11 / Anaconda / BlueStacks
Asynchronous I/O:
By using asyncio and aiofiles, the script can perform I/O operations asynchronously, allowing for more efficient handling of multiple subprocess streams simultaneously. This can be particularly useful when dealing with long-running commands or when responsiveness is crucial. It also helps to avoid deadlocks, since Start-Process allows the redirection of stdout/stdin: -RedirectStandardOutput / -RedirectStandardError
Detached Execution:
The script creates a detached subprocess for running PowerShell commands, which means it operates independently of the parent process. This can be advantageous in scenarios where you need to run commands in the background or interact with PowerShell without blocking the main Python program. Instead of cmd.exe, you can start any other app that loops forever (e.g., a proxy server). The process won't close when Python closes.
Error Handling and Reconnection:
The script includes error handling mechanisms to handle exceptions and reconnect to the subprocess if the connection to stdin is lost. This ensures robustness in scenarios where the subprocess may encounter issues or terminate unexpectedly.
Customization and Control:
The class structure allows for customization of various parameters such as execution policy, working directory, and output redirection. Users can tailor the behavior of the subprocess to suit their specific requirements.
from rlogfi import PowerShellDetachedInteractive
interactivepwsh = PowerShellDetachedInteractive(
executable=r"c:\windows\system32\cmd.exe",
logfolder="c:\\newlogggg",
working_dir=None,
execution_policy="Unrestricted",
arguments=["dir", "c:\\Windows"],
WhatIf="",
Verb="",
UseNewEnvironment="",
Wait="",
stdinadd="",
WindowStyle="Hidden",
)
# executing commandos
stdout, stderr = interactivepwsh.sendcommand("dir")
print(stdout, stderr)
so, se = interactivepwsh.sendcommand("netstat")
so, se = interactivepwsh.sendcommand("cd\\")
so, se = interactivepwsh.sendcommand("ls")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file rlogfi-0.10.tar.gz
.
File metadata
- Download URL: rlogfi-0.10.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d81e8b1459080efdcf3bf4ddd49a2a43586bb3e77ffa79df2fea1db9c8b11750 |
|
MD5 | b9eb3ecfd821307eb2ba0fa810aa1817 |
|
BLAKE2b-256 | 4c6e75793f4e2ab0c93d3ae079c17709ec392e091875c562e3c3be3543c7ec73 |
File details
Details for the file rlogfi-0.10-py3-none-any.whl
.
File metadata
- Download URL: rlogfi-0.10-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47501f63de0aa74cdc97189aeed2bd8979b315fd98107cc6c1b05f9c30afbe0e |
|
MD5 | 44d49b23f9f0e12f885724f9a48bfdc4 |
|
BLAKE2b-256 | 539203f6e970bd9fb6d2507755527a9a393c2d2dd46befb7cf5a3499298b808c |