Interact with subprocesses running both bash.exe (CygWin) and cmd.exe without terminating them.
Project description
Interact with subprocesses running both bash.exe (CygWin) and cmd.exe without terminating them.
pip install cmdbashinteractive
Args:
print_stdout (bool, optional): Whether to print stdout from the subprocess (default is True).
print_stderr (bool, optional): Whether to print stderr from the subprocess (default is True).
limit_stdout (int, optional): Maximum number of lines to keep in stdout history (default is None).
limit_stderr (int, optional): Maximum number of lines to keep in stderr history (default is None).
limit_stdin (int, optional): Maximum number of lines to keep in stdin history (default is None).
convert_to_83 (bool, optional): Whether to convert file paths to short (8.3) format (default is True).
exitcommand (str, optional): The command to signal the subprocess to exit (default is "▓▓▓▓▓▓▓▓▓▓▓").
newline (str, optional): The newline character to use (default is "\n").
getcomspec (str, optional): The command to get the shell executable (default is "bash.exe").
wait_to_complete (float, optional): The time to wait for subprocess completion (default is 0.1 seconds).
**kwargs: Additional keyword arguments for subprocess.Popen.
import os
from cmdbashinteractive import BashInteractive, CmdInteractive
CREATE_NEW_PROCESS_GROUP = 0x00000200
DETACHED_PROCESS = 0x00000008
sh = BashInteractive(
print_stdout=True,
print_stderr=True,
limit_stdout=None,
limit_stderr=None,
limit_stdin=None,
convert_to_83=True,
exitcommand="▓▓▓▓▓▓▓▓▓▓▓",
newline="\n",
getcomspec=r"C:\cygwin\bin\bash.exe",
wait_to_complete=0.1,
shell=False, # **kwargs
creationflags=DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP, # **kwargs
bufsize=0, # **kwargs
env=os.environ.copy(), # **kwargs
)
stdo00, stde00 = sh("ls")
sh.install("tar")
stdo01, stde01 = sh("ping google.com | grep bytes")
stdo02, stde02 = sh(
r"cat C:\yolov5max - Copy\2023_08_17.ini"
) # automatically converted to 8.3 and afterwards to cygwin when convert_to_83 is True
Args:
print_stdout (bool, optional): Whether to print stdout from the subprocess (default is True).
print_stderr (bool, optional): Whether to print stderr from the subprocess (default is True).
limit_stdout (int, optional): Maximum number of lines to keep in stdout history (default is None).
limit_stderr (int, optional): Maximum number of lines to keep in stderr history (default is None).
limit_stdin (int, optional): Maximum number of lines to keep in stdin history (default is None).
convert_to_83 (bool, optional): Whether to convert file paths to short (8.3) format (default is True).
exitcommand (str, optional): The command to signal the subprocess to exit (default is "▓▓▓▓▓▓▓▓▓▓▓").
getcomspec (str, optional): The command to get the shell executable (default is None).
newline (str, optional): The newline character to use (default is "\r\n").
wait_to_complete (float, optional): The interval to check for subprocess completion (default is 0.1 seconds).
**kwargs: Additional keyword arguments for subprocess.Popen.
cmd = CmdInteractive(
print_stdout=True,
print_stderr=True,
limit_stdout=10,
limit_stderr=10,
limit_stdin=10,
convert_to_83=True,
exitcommand="▓▓▓▓▓▓▓▓▓▓▓",
wait_to_complete=0.1,
shell=False, # **kwargs
creationflags=DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP, # **kwargs
bufsize=0, # **kwargs
env=os.environ.copy(), # **kwargs
getcomspec=None,
newline="\r\n",
)
#
strfi = sh(
r"strings C:\yolov5max - Copy\2023_08_17.ini"
) # automatically converted to 8.3 when convert_to_83 is True
stdo0, stde0 = cmd(f"ping google.com", wait_to_complete=0.1)
stdo1, stde1 = cmd(f"dir", wait_to_complete=0.1)
stdo2, stde2 = cmd(f"whoami.exe", wait_to_complete=0.1)
stdo3, stde3 = cmd(
f"ping google.com", wait_to_complete=0
) # non blocking, not recommended - might mess up stdout,stderr
stdo4, stde4 = cmd(
f"dir", wait_to_complete=0
) # non blocking, not recommended - might mess up stdout,stderr
stdo5, stde5 = cmd(
f"whoami.exe", wait_to_complete=0
) # non blocking, not recommended - might mess up stdout,stderr
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
cmdbashinteractive-0.10.tar.gz
(15.3 kB
view details)
Built Distribution
File details
Details for the file cmdbashinteractive-0.10.tar.gz
.
File metadata
- Download URL: cmdbashinteractive-0.10.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9a505abf66aba21ec9713503e992614cc1af44d52e0b3b45a19015888cb0d1a |
|
MD5 | 093ffbd7bfbd6e584377f0082ade10fb |
|
BLAKE2b-256 | ca0b75e1722b11cd7323500b130f99efdd1cc4da75b52d67ebd285a9142e9f27 |
File details
Details for the file cmdbashinteractive-0.10-py3-none-any.whl
.
File metadata
- Download URL: cmdbashinteractive-0.10-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdcc9df49c60da7b8d3489419bdb0310493d8fe13096cd1fc33bd9bbd869afd8 |
|
MD5 | fb5033f160fffaa91110bcfc12e0303d |
|
BLAKE2b-256 | 19f128d8a587c15a2c12004bd2afaa61a73a69cde83cb424dbbf8d690adeedbd |