Interacting with UE4 Editor by commandline - best practice

Hi there!

We would like to integrate UE4 more into our pipeline. We’re particularly interested in automating UE4 related processes via commandline and python scripts. I’ve had a look at the existing documentation:

I’ve got a few questions there:

  • What’s the difference between UE4Editor.exe and UE4Editor-Cmd.exe? They both seem to behave the same, and both bring up the GUI. Any preference on which one to use when using UE4 ‘headless’ via the command line?
  • How to get logging output from UE4 when using it via the commandline? By default it seems to by totally silent and doesn’t output to stdout or stderr. In order to interact with it properly vie the commandline, we’d need to be able to capture output logging.

Ideally we’d be calling it from within other (non-UE4) Python processes like this:

result = subprocess.call('UE4Editor-Cmd.exe -run=pythonscript -script="c:\my_script.py"', stdout=subprocess.PIPE, stderr=subprocess.PIPE )

Any advice on best practice there?
Any help much appreciated!

1 Like

This is pretty old but since there were no answers and I ran into the same problem, I’ll share what I learned.

  1. I know that UE4Editor.exe is the full editor and UE4Editor-Cmd.exe “commandlet mode” and intended to run UCommandlets I wasn’t able to get it to successfully run a commandlet though. I’m not sure if it was my game code or not. I decided to run UE4Editor.exe with -nullrhi to run it headless.
  2. I was able to get standard output by passing -stdout to UE4Editor.exe. I don’t know why this isn’t documented on Command-Line Arguments in Unreal Engine | Unreal Engine 5.1 Documentation . I only figured it out after I found this page for a python CLI wrapper https://adamrehn.com/docs/ue4cli/descriptor-commands/run that mentioned a -stdout flag.

I am also having issues running UEditor -Cmd.exe in because of Oculus failing to initialize in Commandlet mode.
Do you have exact syntax for running UE4Editor.exe in headless mode, and executing a Python script?

I don’t know what you mean by executing a Python script, but the syntax I used was: UE4Editor.exe MyProjectName -nullrhi -stdout -ExecCmds=“My Exec Command;”

1 Like

I was attempting to use this syntax to run a Python script in Commandlet mode:
UE4Editor-Cmd.exe “C:\projects\MyProject.uproject” -run=pythonscript -script=“c:\my_script.py”

Fails because Oculus is unable to initialize in Commandlet mode:
LogOnline: Warning: Oculus: Failed to initialize the Oculus Platform SDK! Failure code: -5
LogOnline: Warning: Oculus: Oculus API failed to initialize!

Was looking for another was to run the UE4Editor from command line, and execute a Python script?

Has there been update on this. I created a script but it works in the editor just find but when I try to run it headless it tends to crash.

To answer your first question:
UE4Editor.exe is the editor itself. UE4Editor-Cmd.exe is the command-line for the editor. I’m actually really surprised to hear that UE4Editor-Cmd.exe is opening up the GUI for you. I’ve had it open “live coding” before, but that’s about it.

  1. I’m not sure about how to do this in Python, but here’s a way of doing it in C#, maybe you can figure it out how to convert that to Python.
Process myProcess = new Process();
Process myProcess = new Process();
myProcess .StartInfo.FileName = UE4EditorCmd; //Relative path to UE4Editor.exe
myProcess .StartInfo.Arguments =  "myProject.uproject -run=pythonscript"
myProcess .ErrorDataReceived += MyErrorFunc;
myProcess .OutputDataReceived += MyOutputFunc;

myProcess .Start();

myProcess.BeginErrorReadLine();
myProcess.BeginOutputReadLine();
try
{
	if (myProcess.WaitForExit(maxTime))
	{
      //test for different results. A result of 1, 2 or 3 doesn't mean it failed.
     //A result with a negative number means it crashed.

}



        internal static void MyErrorFunc(object _sender, DataReceivedEventArgs _event)
        {
            Console.WriteLine(_event.Data);
        }


//Same idea for MyOutputFunc