The Command Line
If you start the Unreal Editor from the command line or from a script, you can specify a Python script file in the command line arguments. If your Python script requires additional command-line arguments, include them after the name of your script.
There are two different ways to run a Python script from the command line. In both approaches, the Editor shuts down immediately after running your Python script.
Option 1: Full Editor
In this approach, the full Unreal Editor launches, opens your specified Project, loads the default startup level, then runs your Python script once everything is loaded and ready. This approach is good if you need your script to interact with content in your Project or in a Level that can take some time to load.
ExecutePythonScript argument to the command line, and set its value to the Python script you want to run. For example:
> UE4Editor-Cmd.exe MyProject.uproject -ExecutePythonScript="c:\my_script.py"
The approach above requires that you enable the Editor Scripting Utilities plugin for your Project.
Option 2: Commandlet
In this approach, the Editor starts up with a minimal environment, without UI or rendering. This approach is very fast to execute, and can even run your scripts in headless mode without opening the Editor UI, but it can be trickier to load Levels and other kinds of Assets that your script needs to interact with.
Add the following arguments to the command line:
> UE4Editor-Cmd.exe -run=pythonscript -script="c:\my_script.py"