Skip to content

Commit 4432ad0

Browse files
authored
lol
0 parents  commit 4432ad0

File tree

11 files changed

+177
-0
lines changed

11 files changed

+177
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Arran Hewitt.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
thanks for using!
2+
3+
4+
# batch syntax in python
5+
idk how i made this
6+
it was funny ngl
7+
8+
# bye

build/lib/pybatch99/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .core import run_batch
2+
3+
__all__ = ["run_batch"]

build/lib/pybatch99/core.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import subprocess
2+
3+
def run_batch(command: str, *, new_window=False, capture_output=False):
4+
"""
5+
Execute a Windows batch command.
6+
7+
Args:
8+
command (str): The batch command to run.
9+
new_window (bool): If True, runs in a new CMD window.
10+
capture_output (bool): If True, returns stdout/stderr from the command.
11+
12+
Returns:
13+
subprocess.CompletedProcess or None
14+
"""
15+
if new_window:
16+
subprocess.Popen(
17+
["cmd", "/k", command],
18+
creationflags=subprocess.CREATE_NEW_CONSOLE
19+
)
20+
return None
21+
else:
22+
return subprocess.run(
23+
command,
24+
shell=True,
25+
text=True,
26+
capture_output=capture_output
27+
)

build/lib/tests/test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from pybatch99 import run_batch
2+
3+
result = run_batch("echo Hello && pause")
4+
print(result)

pybatch99/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .core import run_batch
2+
3+
__all__ = ["run_batch"]

pybatch99/core.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import subprocess
2+
3+
def run_batch(command: str, *, new_window=False, capture_output=False):
4+
"""
5+
Execute a Windows batch command.
6+
7+
Args:
8+
command (str): The batch command to run.
9+
new_window (bool): If True, runs in a new CMD window.
10+
capture_output (bool): If True, returns stdout/stderr from the command.
11+
12+
Returns:
13+
subprocess.CompletedProcess or None
14+
"""
15+
if new_window:
16+
subprocess.Popen(
17+
["cmd", "/k", command],
18+
creationflags=subprocess.CREATE_NEW_CONSOLE
19+
)
20+
return None
21+
else:
22+
return subprocess.run(
23+
command,
24+
shell=True,
25+
text=True,
26+
capture_output=capture_output
27+
)

pyproject.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[build-system]
2+
requires = ["setuptools>=77", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "pybatch99"
7+
version = "1.0.3"
8+
description = "Use full Windows batch (.bat) and CMD syntax from Python."
9+
readme = "README.md"
10+
requires-python = ">=3.7"
11+
license = "MIT"
12+
license-files = ["LICENSE"]
13+
14+
authors = [
15+
{ name = "Arran Hewitt" }
16+
]
17+
18+
classifiers = [
19+
"Programming Language :: Python :: 3",
20+
"Programming Language :: Python :: 3.7",
21+
"Programming Language :: Python :: 3.8",
22+
"Programming Language :: Python :: 3.9",
23+
"Programming Language :: Python :: 3.10",
24+
"Operating System :: Microsoft :: Windows",
25+
"Development Status :: 5 - Production/Stable",
26+
"Intended Audience :: Developers",
27+
"Topic :: Software Development :: Libraries :: Python Modules"
28+
]
29+
30+
[project.urls]
31+
Homepage = "https://pypi.org/project/pybatch99"
32+
Repository = "https://github.com/epicinver/pybatch99"
33+
Issues = "https://github.com/epicinver/pybatch99/issues"
34+
35+
[tool.setuptools.packages.find]
36+
where = ["."]

setup.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name="batch4py",
5+
version="1.0.3",
6+
description="Batch and Windows CMD syntax for Python.",
7+
author="Arran Hewitt",
8+
packages=find_packages(), # Will auto-detect 'batch4py'
9+
install_requires=[],
10+
classifiers=[
11+
"Programming Language :: Python :: 3",
12+
"Operating System :: Microsoft :: Windows",
13+
],
14+
)

tests/inpython.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from pybatch99 import run_batch
2+
3+
def test_echo():
4+
result = run_batch("echo Hello from batch, inside of python!", capture_output=True)
5+
assert "Hello from batch, inside of python!" in result.stdout
6+
7+
def test_new_window():
8+
# This should open a new CMD window and run the command.
9+
# It won't return anything to the current script.
10+
run_batch("echo Hello in python using new window is false && pause", new_window=False)
11+
12+
if __name__ == "__main__":
13+
print("[*] Testing...")
14+
test_new_window()
15+
print("[✓] Tested.")

0 commit comments

Comments
 (0)