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

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>")

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

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

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, then your code does something if you enter:
py winver.exe test

There are ways of compiling 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