Python command line arguments not being accepted

Hi,

I’m trying to read command line arguments using the following code

import argparse
parser = argparse.ArgumentParser()
parser.add_argument('vrscene', help='VRay Scene to process')
command_line_args = parser.parse_args()
print (command_line_args)

But i get a python error anytime I add anything at the end of the script invocation through the output log i.e ‘py myscript.py’ . If i try to execute ‘py myscript.py --vrscene test’ or ‘py myscript.py anytext’ i get a string error. Seems like its not accepting anything after the name of the script.

My end goal is to be able to supply command line args through command line invocation i.e 'UE4Editor-Cmd.exe myproject.uproject ExecutePythonScript=“myscript.py --vrscene test”

How can I do this ?

Thanks,

1 Like

You didn’t provide the correct settings to add_argument.

This work when being run from an Editor Blueprint inheriting from Editor Utility Actor, I guess it should work as well from the command line.

# Get raw arguments
import sys
unreal.log(f"Python command RAW arguments: {sys.argv}")

# Parse arguments
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--vrscene', help='VRay Scene to process')
args = parser.parse_args()
unreal.log(f"vrscene={args.vrscene}")

# Output
LogPython: vrscene=test