subprocconout


Namesubprocconout JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/subprocconout
Summaryrun a subprocess and capture its CONOUT$ console output
upload_time2024-02-02 00:46:13
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords conout capture
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# 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.",
#     ],
# ]
		
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/subprocconout",
    "name": "subprocconout",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "CONOUT,capture",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6c/bf/67b3e97bb833d5765fe64d3d7089c1c201a52ae9ac5347caba301aa349bb/subprocconout-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# run a subprocess and capture its CONOUT$ console output\r\n\r\n## Tested against Windows / Python 3.11 / Anaconda\r\n\r\n## pip install subprocconout\r\n\r\n```\r\nsubprocess_conout(*args, nrows=9999, encode=True, **kwargs):\r\n    Function to run a subprocess and capture its CONOUT$ console output.\r\n\r\n    Args:\r\n        *args: Variable length argument list.\r\n        nrows: Number of rows to capture from the console output (default is 9999).\r\n        encode: Boolean indicating whether to encode the console output (default is True).\r\n        **kwargs: Variable length keyword argument list.\r\n\r\n    Returns:\r\n        The captured console output.\r\n\t\t\r\nfrom subprocconout import subprocess_conout\r\nimport textwrap\r\n# based on https://stackoverflow.com/a/38749458/15096247\r\ntext = textwrap.dedent(\r\n    \"\"\"\\\r\n    Lorem ipsum dolor sit \u00e4\u00e7amet, consectetur adipiscing elit, sed do\r\n    eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut\r\n    enim ad minim veniam, quis nostrud exercitation ullamco laboris\r\n    nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor\r\n    in reprehenderit in voluptate velit esse cillum dolore eu\r\n    fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\r\n    proident, sunt in culpa qui officia deserunt mollit anim id est\r\n    laborum.\"\"\"\r\n)\r\n\r\ncmd = (\r\n    'python -c \"'\r\n    \"print('piped output');\"\r\n    \"conout = open(r'CONOUT$', 'w');\"\r\n    \"conout.write('''%s''')\\\"\" % text\r\n)\r\n\r\nresult = subprocess_conout(cmd, nrows=9999, encode=True)\r\nprint([[q for q in line.split(b\"\\x00\") if q] for line in result if line])\r\n\r\n# [\r\n#     [\r\n#         b\"Lorem ipsum dolor sit \\x84\\x87amet, consectetur adipiscing elit, sed do\",\r\n#         b\"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut\",\r\n#     ],\r\n#     [\r\n#         b\"enim ad minim veniam, quis nostrud exercitation ullamco laboris\",\r\n#         b\"nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor\",\r\n#     ],\r\n#     [\r\n#         b\"in reprehenderit in voluptate velit esse cillum dolore eu\",\r\n#         b\"fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\",\r\n#     ],\r\n#     [\r\n#         b\"proident, sunt in culpa qui officia deserunt mollit anim id est\",\r\n#         b\"laborum.\",\r\n#     ],\r\n# ]\r\n\t\t\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "run a subprocess and capture its CONOUT$ console output",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/subprocconout"
    },
    "split_keywords": [
        "conout",
        "capture"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3bea3ddf943071af66f6889ab523f10343f589c35403bc3dac81040c346645cb",
                "md5": "7cf5801cdac7c27fc19cc79fabc398b0",
                "sha256": "a697bcc528efed52612018176e00e5fdb75ee411fe5efd573046aa5d5d972722"
            },
            "downloads": -1,
            "filename": "subprocconout-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7cf5801cdac7c27fc19cc79fabc398b0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6675,
            "upload_time": "2024-02-02T00:46:11",
            "upload_time_iso_8601": "2024-02-02T00:46:11.710820Z",
            "url": "https://files.pythonhosted.org/packages/3b/ea/3ddf943071af66f6889ab523f10343f589c35403bc3dac81040c346645cb/subprocconout-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6cbf67b3e97bb833d5765fe64d3d7089c1c201a52ae9ac5347caba301aa349bb",
                "md5": "3ee64cb8cf885bcb2678e10dcd062bcd",
                "sha256": "00d529d6a4225e56d5efd9a20e7c3fbf559afb9c5c5df7fb3cac27f6bd2f216f"
            },
            "downloads": -1,
            "filename": "subprocconout-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "3ee64cb8cf885bcb2678e10dcd062bcd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5369,
            "upload_time": "2024-02-02T00:46:13",
            "upload_time_iso_8601": "2024-02-02T00:46:13.576709Z",
            "url": "https://files.pythonhosted.org/packages/6c/bf/67b3e97bb833d5765fe64d3d7089c1c201a52ae9ac5347caba301aa349bb/subprocconout-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-02 00:46:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "subprocconout",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "subprocconout"
}
        
Elapsed time: 0.22552s