Is there a way to run an exe command through the command prompt?

What I want to do is run a command from an .exe in the Windows command prompt like this

...\test.exe cmd
test

The idea is that on the command prompt, you writer “test.exe cmd” and then the program will print “test”. I’ve had a go at this myself and tested it, then failed miserably.

import sys  # Imports the 'sys' module, which allows access to the command line arguments.
import subprocess  # Imports the 'subprocess' module, which allows you to run external commands.

if len(sys.argv) != 3:
    print("Usage: test.exe <command>")
    sys.exit(1)

executable = sys.argv[1]  # path to the .exe
command = sys.argv[2]     # command

if command == "test":
    try:
        subprocess.run([executable, command], check=True)
        print("test")
    except subprocess.CalledProcessError as e:
        print(f"Error running {executable}: {e}")
        sys.exit(1)

All it does is display “Usage: test.exe ” so far.

If all your program really wants to do is print “test”, you’ve over complicated it massively.

If you save your script as run_exe.py, then your code does something if you enter:
py run_exe.py winver.exe test

There are ways of compiling run_exe.py into run_exe.exe (if you will accept a 30 - 50 MB minimum for a Hello World program), e.g. PyInstaller Manual — PyInstaller 5.13.2 documentation