Importable CLI-passthrough with bells and whistles.
Project description
README
This project provides an entry point cli-passthrough
in the terminal that accepts any amount of parameters, and runs those parameters as it's own command. Except in a few special cases, this will output to the terminal exactly what the command would have, including any formatting done with escape sequences. Both the combined stdout and stderr are logged, with order preserved, in logs/history.log
, and the stderr by itself is logged in /logs/stderr.log
. These log files are written to in realtime. The output to the terminal is also in realtime.
This project was motivated by making a wrapper on another application which needed to be used over the CLI. I wanted to also use the wrapper from the CLI as well. I wanted to see the output of the program I was invoking in real-time, in the same formatting, and log everything. In other words, I wanted the following:
- ANY COMMAND: Run nearly any command given to it.
- FLEXIBLE LOGGING: Capture stdout and stderr independently for flexible logging.
- ORDER PESERVATION: Preserve order of stdout and stderr
- REALTIME OUTPUT: Output to the screen in realtime, i.e. don't wait for the command to exit before dumping to the screen.
- EXIT STATUS: Capture exit code
- FORMATTING PRESERVED: Preserve ANSI escape sequences so most things are still formatted as if not run through this passthrough.
- INTERACTIVE, i.e. allow prompting for input.
1 | 2 | 3 | 4 | 5 | 6 | 7 | note | |
---|---|---|---|---|---|---|---|---|
os.system | Y | N | Y | Y | Y | Y | Y | Doesn't capture output at all |
os.popen | N | N | Y | N | N | Y | N | Deprecated & obsolete |
os.exec* | Y | N | - | N | N | N | N | Really not the intended use |
pexpect | Y | N | Y | Y | Y | Y | Y | Bad logging |
subprocess.popen + threads | Y | Y | Y | N | Y | Y/N | N | Threads just enable separate logging, not realtime output |
subprocess.popen + pty | Y | Y | Y | Y | Y | Y | Y | We got it! |
Known Limitations
This implementation of subprocess.popen + pty currently has the following limitations:
-
It doesn't run every command, just most.
ssh
doesn't work :/ -
It makes assumptions about the terminal size. It would be better if it detected the terminal the python is ran in, and use the same dimensions.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for CLI_passthrough-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98bf5e8142049424cb08b654e4c0646b9e6bd50e1196f8a555ce54a54d3597a0 |
|
MD5 | 53f3eaef5e423a859e9f5356eba908e3 |
|
BLAKE2b-256 | ec324109fd6e896172da80a7b2fccd8280c6f63c8aab689e685e51cb20f50f8c |