Executes Cygwin bash scripts/commands in Python, captures and prints the output
pip install cygsubprocess
Tested against Windows 10 / Python 3.10 / Anaconda / cygcheck (cygwin) 3.4.6
from cygsubprocess import Bashsubprocess
ba = Bashsubprocess(
cygfolder=r'C:\cygwin',mirrorsite=None,addtopath=True
) # If cygwin is not installed, it will be installed and added to the PATH
ba.convert_path_cyg2win("/cygdrive/c/Users/hansc/Downloads/ClipAngel 2.09")
# r'C:\Users\hansc\Downloads\ClipAngel 2.09'
ba.convert_path_win2cyg(path=r"C:\Users\hansc\Downloads\ClipAngel 2.09")
# '/cygdrive/c/Users/hansc/Downloads/ClipAngel 2.09'
cmd1 = ba.execute_capture("ls -la")
print(cmd1.stdout_lines[:5])
cmd2 = ba.execute_capture(["ls -la | grep 'py'"])
print(cmd2.stdout_lines[:5])
cmd1 = ba.execute_print_capture("ls -la")
print(cmd1.stdout_lines[:5])
cmd2 = ba.execute_print_capture(["ls -la | grep 'py'"])
print(cmd2.stdout_lines[:5])
# gist download
scriptexec = r"""
slugify(){ echo "$1" | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z; }
cnt=0; gh gist list --limit 3 | cut -f1,2 | tac | while read id name; do ((cnt++)); gh gist clone $id $cnt-`slugify "$name"`; done
"""
cmd4 = ba.execute_print_capture(scriptexec)
print(cmd4.stdout_lines)
bashscr = """
#!/bin/bash
# set the STRING variable
STRING="Hello World!"
# print the contents of the variable on screen
echo $STRING
"""
bashtofile = ba.exec_sh_to_file(bashscr, printoutput=False)
print(bashtofile.stdout_lines)
bashscr = r"""
#!/bin/bash
salary=1000
expenses=800
#Check if salary and expenses are equal
if [ $salary == $expenses ];
then
echo "Salary and expenses are equal"
#Check if salary and expenses are not equal
elif [ $salary != $expenses ];
then
echo "Salary and expenses are not equal"
fi
"""
bashtofile2 = ba.exec_sh_directly(bashscr, printoutput=True)
print(bashtofile2.stdout_lines)
scriptfile='c:\\bashscripttest.sh'
with open(scriptfile,mode='w', encoding='utf-8',newline='\n') as f:
f.write(bashscr)
ba.installapt() # install apt https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg
ba.apt_install( package='hunspell-de') # install a package with apt
ba.apt_remove( package='hunspell-de') # remove a package with apt
test2=ba.exec_sh_url( bashscr=r'https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg', printoutput=True)
test3=ba.exec_sh_file( bashscr=scriptfile, printoutput=True)
test4=ba.exec_sh_to_file( bashscr, printoutput=True)
test5=ba.exec_sh_directly( bashscr, printoutput=True)
test6=ba.get_list_of_files_no_stat( folder=r'C:\Python34') # windows and cyg path (escaped and unescaped)
test7=ba.get_list_of_files_with_stat( folder=r'C:\Python34') # windows and cyg path (escaped and unescaped)
....
# b'-rwxr-x---+ 1 Administrators hansc 25749 Mar 31 23:52 trayinfo.py.bak\n'
# b'-rwxr-x---+ 1 Administrators hansc 671 Apr 1 09:50 trayinfotest.py\n'
# b'-rwxr-x---+ 1 Administrators hansc 25878 Apr 1 09:34 traymenuxxxxxxxxxx.py\n'
# b'-rwxr-x---+ 1 Administrators hansc 4329 Apr 1 03:12 tw.py\n'
# b'-rwxr-x---+ 1 Administrators hansc 8095 Apr 1 08:48 win10ctypestoastxxxxxxxxxx.py\n'
# [b'drwxr-x---+ 1 hansc hansc 0 Apr 1 13:01 1-pyde-py\n', b'drwxr-x---+ 1 hansc hansc 0 Apr 1 13:14 1-stra-py\n', b'drwxr-x---+ 1 hansc hansc 0 Apr 1 13:14 10-cygwinco-py\n', b'drwxr-x---+ 1 hansc hansc 0 Apr 1 13:01 10-tracealllines-py\n', b'drwxr-x---+ 1 hansc hansc 0 Apr 1 13:01 2-stra-py\n']
# b"Cloning into '1-tracealllines-py'...\n"
# b"Cloning into '2-cygwinco-py'...\n"
# b"Cloning into '3-cygwinco-py'...\n"
# []
# [b'Hello World!\n']
# b'Salary and expenses are not equal\n'
# [b'Salary and expenses are not equal\n']
....
Metadata
Release files for cygsubprocess 0.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cygsubprocess-0.12.tar.gz | 18.8 kB | Without provenance | Details for cygsubprocess-0.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cygsubprocess-0.12-py3-none-any.whl | Python 3 | none | any | Details for cygsubprocess-0.12-py3-none-any.whl |
Total release size: 39.3 kB
Release files / cygsubprocess-0.12.tar.gz
| Download URL | cygsubprocess-0.12.tar.gz |
|---|---|
| Size | 18.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f6d843f777c0e9ef31cc55588e0958898e174eb39c09fed7fea36dbf0e60b0b9
|
|
BLAKE2b-256 checksum How to use checksums |
8d9bda8f4052bcecccd4401fba567404d013395d9a2996d8410e36cee7fa2f63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Release files / cygsubprocess-0.12-py3-none-any.whl
| Download URL | cygsubprocess-0.12-py3-none-any.whl |
|---|---|
| Size | 20.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f964a91c8a449b8c0849ee40de37505fdef76190430eec484646bf916f8ae47
|
|
BLAKE2b-256 checksum How to use checksums |
7a305083a52f5b9cad1a0cdba8c704ecc12131ef1f2a55c334025e061a1add46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Security for cygsubprocess 0.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.