UE4Editor-Cmd.exe python script with spaces in path

There is a space in the path to my python script. I feel like I’ve tried everything for escaping these spaces (Linux and Windows style escapes using backslashes, ^, and all sorts of quotes and quote escapes). The command runs fine when the path as no space in it. Here’s the command used :

"C:\Program Files\Epic Games\UE_4.27\Engine\Binaries\Win64\UE4Editor-Cmd.exe" "path\to\myproject.uproject" -stdout -FullStdOutLogOutput -run=pythonscript -script="C:\path with spaces\to\my\script.py" | FINDSTR "LogPython"

Depending on the style of escaping I either get :

  • Error: SyntaxError: unexpected character after line continuation character (<string>, line 1)

  • Error: SyntaxError: invalid syntax (<string>, line 1)

  • Error: -Script argument not specified

Some of the path style I’ve tried :

  • "C:\\path\ with\ spaces\\to\\my\\script.py"

  • "C:/path with spaces/to/my/script.py"

  • \"C:\path with spaces\to\my\script.py\"

  • C:\path^ with^ spaces\to\my\script.py

  • " 'C:/path with spaces/to/my/script.py' "

  • multiple combination of those

The community wiki mentions this in the pitfall section but without explaining the fix.

Other useful ressources : Unreal doc

Thanks a lot for any insight.

1 Like

// The code needs to manage spaces and quotes. The scripts pathname and the script arguments are passed to the ‘PY’
// command which are passed to Python plugin for execution. Below shows how to quotes the script pathname
// and the scripts arguments when they contain spaces.
// ±----------------------------------------------------------------------------------±--------------------------------------------------+
// | Command Line Parameters | Resulting “PY” command |
// ±----------------------------------------------------------------------------------±--------------------------------------------------+
// | -ExecutePythonScript=script.py | PY script.py |
// | -ExecutePythonScript=“script.py” | PY script.py |
// | -ExecutePythonScript=“C:/With Space/with space.py” | PY C:/With Space/with space.py |
// | -ExecutePythonScript=“script.py arg1” | PY script.py arg1 |
// | -ExecutePythonScript=“script.py arg1 \"args with space\"” | PY script.py arg1 “args with space” |
// | -ExecutePythonScript=“C:\With Space\with space.py \"arg with space\"” | PY C:/With Space/with space.py “arg with space” | NOTE: The Python plugin parses up the “.py” and manages the spaces in the pathname.
// | -ExecutePythonScript=“\"C:/With Space/with space.py\" \"arg with space\"” | PY “C:/With Space/with space.py” “arg with space” |
// ±----------------------------------------------------------------------------------±--------------------------------------------------+

–Hey, guys, there’s instructions in the source code