Skip to main content

run a subprocess and capture its CONOUT$ console output

Project description

run a subprocess and capture its CONOUT$ console output

Tested against Windows / Python 3.11 / Anaconda

pip install subprocconout

subprocess_conout(*args, nrows=9999, encode=True, **kwargs):
    Function to run a subprocess and capture its CONOUT$ console output.

    Args:
        *args: Variable length argument list.
        nrows: Number of rows to capture from the console output (default is 9999).
        encode: Boolean indicating whether to encode the console output (default is True).
        **kwargs: Variable length keyword argument list.

    Returns:
        The captured console output.
		
from subprocconout import subprocess_conout
import textwrap
# based on https://stackoverflow.com/a/38749458/15096247
text = textwrap.dedent(
    """\
    Lorem ipsum dolor sit äçamet, consectetur adipiscing elit, sed do
    eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
    enim ad minim veniam, quis nostrud exercitation ullamco laboris
    nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu
    fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est
    laborum."""
)

cmd = (
    'python -c "'
    "print('piped output');"
    "conout = open(r'CONOUT$', 'w');"
    "conout.write('''%s''')\"" % text
)

result = subprocess_conout(cmd, nrows=9999, encode=True)
print([[q for q in line.split(b"\x00") if q] for line in result if line])

# [
#     [
#         b"Lorem ipsum dolor sit \x84\x87amet, consectetur adipiscing elit, sed do",
#         b"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut",
#     ],
#     [
#         b"enim ad minim veniam, quis nostrud exercitation ullamco laboris",
#         b"nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor",
#     ],
#     [
#         b"in reprehenderit in voluptate velit esse cillum dolore eu",
#         b"fugiat nulla pariatur. Excepteur sint occaecat cupidatat non",
#     ],
#     [
#         b"proident, sunt in culpa qui officia deserunt mollit anim id est",
#         b"laborum.",
#     ],
# ]
		

Project details


Release history Release notifications | RSS feed

This version

0.10

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

subprocconout-0.10.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

subprocconout-0.10-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file subprocconout-0.10.tar.gz.

File metadata

  • Download URL: subprocconout-0.10.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for subprocconout-0.10.tar.gz
Algorithm Hash digest
SHA256 00d529d6a4225e56d5efd9a20e7c3fbf559afb9c5c5df7fb3cac27f6bd2f216f
MD5 3ee64cb8cf885bcb2678e10dcd062bcd
BLAKE2b-256 6cbf67b3e97bb833d5765fe64d3d7089c1c201a52ae9ac5347caba301aa349bb

See more details on using hashes here.

File details

Details for the file subprocconout-0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for subprocconout-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 a697bcc528efed52612018176e00e5fdb75ee411fe5efd573046aa5d5d972722
MD5 7cf5801cdac7c27fc19cc79fabc398b0
BLAKE2b-256 3bea3ddf943071af66f6889ab523f10343f589c35403bc3dac81040c346645cb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page