Skip to main content

pycmd

用 Python 实现的 Windows CMD / BAT 兼容解释器,支持变量展开、批处理调用、条件、循环、管道、重定向和常用文件命令。要求 Python 3.10+,核心无需第三方运行时依赖。

分发包名为 wincmd,导入包和命令名均为 pycmd。

安装与运行

在源码目录安装:

python -m pip install .
pycmd -c "echo hello"
pycmd --batch examples/countdown.bat
python -m pycmd --help

不传命令或脚本时进入交互模式。外部程序执行需显式添加 --allow-external。解释器会按脚本执行文件操作,不是沙箱,只应运行可信脚本。

POSIX CLI 默认使用 UTF-8;旧 GBK 脚本可用 --codepage 936。--delayed 开启延迟展开,--traceback 显示批处理调用栈,--max-steps 和 --timeout 可约束执行。--xp 提供旧式中文控制台字符宽度适配。

可选 Tk 图形控制台:

python -m pip install '.[gui]'
pycmd --gui --fontsize 20 --batch examples/countdown.bat

GUI 需要宿主安装 Tk 和可用的图形显示。Pillow 由 gui 扩展安装。支持文字、图片层、鼠标和滚动历史;窗口尺寸、终端输入和字体效果依赖宿主。

Python API

from pycmd import Runtime

runtime = Runtime(env={"VALUE": "hello"})
status = runtime.command("echo %VALUE%")
output = runtime.streams.table[1].getvalue()
assert status == 0
assert output == b"hello\r\n"

兼容范围包括 CMD 常用语法及部分外部工具适配。系统查询使用虚拟兼容值,部分环境依赖命令只实现基础行为;不保证所有 Windows 脚本或所有宿主下逐字节兼容。内置帮助是项目自行编写的简明说明。

开发与验证

python -m pip install -e '.[dev,gui]'
python -m unittest discover -s tests -v
python -m pycmd.replay --round all --all
python tools/check_public_tree.py
python tools/build_release.py
python -m twine check dist/*

无图形显示时,需真实窗口的测试会跳过。Linux 可用 xvfb-run -a python -m unittest discover -s tests -v 验证 GUI。发布包中的解释器不依赖测试数据;回放工具需要源码目录中的 tests,可通过 --data-dir 指定。

公开测试保留独立行为断言和精选的冻结输出,不包含原始机器采集记录或第三方应用源码。详见 测试说明、公开化整理说明 和 发布步骤。

许可

MIT。

Metadata

Release files for wincmd 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wincmd 0.2.0
File Size Uploaded Provenance
wincmd-0.2.0.tar.gz 113.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for wincmd 0.2.0
File Interpreter ABI Platform
wincmd-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 200.6 kB

Release files / wincmd-0.2.0.tar.gz

Download URL wincmd-0.2.0.tar.gz
Size 113.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ace0c185ecd375bb22c792ab42462c8a02479e25c4f2e66d190da1d54eb3ac07
BLAKE2b-256 checksum
How to use checksums
9781c0b8d919fbd0b14a2b22f3119247b2939a550e0533baff2176b5c4ec5c36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.8

Release files / wincmd-0.2.0-py3-none-any.whl

Download URL wincmd-0.2.0-py3-none-any.whl
Size 87.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a05469a7be4ab65ff7e3de01dd0a24dedb548352bc22584bb55eea520421561
BLAKE2b-256 checksum
How to use checksums
60eba7eb6c29b62be9937e1c7cbc572829fdea1b4644b933e1c0e9d35ad08d67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.8

Security for wincmd 0.2.0

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page