CommandLineArguments

CommandLineArguments

#Overview

name: CommandLineArguments

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 15 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of CommandLineArguments is to handle and process command-line arguments passed to an Unreal Engine application or tool. It is used across various subsystems and modules within the engine to customize behavior and settings at runtime.

Key points about CommandLineArguments:

  1. It’s used in multiple Unreal Engine subsystems, including the editor, build tools, crash reporting, and multi-user server.

  2. The value of these arguments is typically set when launching the application or process. They can be passed from the operating system, a launcher, or programmatically within the engine.

  3. CommandLineArguments often interact with other configuration systems in Unreal Engine, such as project settings or engine configuration files.

  4. Developers must be aware that some command-line arguments can significantly alter the behavior of the engine or tools, so they should be used carefully and documented properly.

  5. Best practices for using CommandLineArguments include:

    • Documenting all supported command-line arguments in your project
    • Using consistent naming conventions for your custom arguments
    • Validating and sanitizing input from command-line arguments to prevent security issues
    • Considering the use of configuration files for complex settings instead of long command lines
  6. CommandLineArguments are particularly useful for automation, debugging, and customizing behavior in different environments (e.g., development vs. production).

  7. In some cases, such as with the World Partition Builder or the Crash Report Client, CommandLineArguments are used to launch separate processes with specific configurations.

  8. The engine provides utility functions and classes to parse and handle command-line arguments, making it easier for developers to work with them consistently across different modules.

When using CommandLineArguments, developers should ensure they understand the impact of each argument on the system and use them judiciously to maintain clear and manageable application behavior.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Plugins/Editor/DisplayClusterLaunch/Config/BaseDisplayClusterLaunch.ini:4, section: [/Script/DisplayClusterLaunchEditor.DisplayClusterLaunchEditorProjectSettings]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/Editor/DisplayClusterLaunch/Source/DisplayClusterLaunchEditor/Private/DisplayClusterLaunchEditorModule.cpp:796

Scope (from outer to inner):

file
function     void FDisplayClusterLaunchEditorModule::GetProjectSettingsArguments

Source code excerpt:

{
	{
		for (const FString& CommandLineArgument : ProjectSettings->CommandLineArguments)
		{
			if (!CommandLineArgument.IsEmpty())
			{
				ConcatenatedCommandLineArguments += FString::Printf(TEXT(" -%s "), *CommandLineArgument);
			}
		}

#Loc: <Workspace>/Engine/Plugins/Editor/DisplayClusterLaunch/Source/DisplayClusterLaunchEditor/Public/DisplayClusterLaunchEditorProjectSettings.h:98

Scope (from outer to inner):

file
function     class DISPLAYCLUSTERLAUNCHEDITOR_API UDisplayClusterLaunchEditorProjectSettings : public UObject { GENERATED_BODY

Source code excerpt:

	 * Where to store the Unreal Insights Trace Files.
	 * If empty, Unreal Insights will connect to localhost (this computer) instead and you'll need to ensure Unreal Insights is launched.
	 * To specify a socket to connect to, use CommandLineArguments.
	 */
	UPROPERTY(Config, EditAnywhere, Category="nDisplay Launch Settings|Unreal Insights", meta = (EditCondition="bEnableUnrealInsights"))
	FDirectoryPath ExplicitTraceFileSaveDirectory;

	/**
	 * A Console Variables Asset to always apply to your launches.
	 * All saved commands and variables will be executed before "Additional" ones specified below.
	 */
	UPROPERTY(Config, EditAnywhere, Category="nDisplay Launch Settings|Console", meta = (AllowedClasses="/Script/ConsoleVariablesEditorRuntime.ConsoleVariablesAsset"))
	FSoftObjectPath ConsoleVariablesPreset;

#Loc: <Workspace>/Engine/Plugins/Editor/DisplayClusterLaunch/Source/DisplayClusterLaunchEditor/Public/DisplayClusterLaunchEditorProjectSettings.h:133

Scope (from outer to inner):

file
class        class UDisplayClusterLaunchEditorProjectSettings : public UObject

Source code excerpt:

	 */
	UPROPERTY(Config, EditAnywhere, Category="nDisplay Launch Settings|Console")
	TSet<FString> CommandLineArguments;

	/**
	 * The name of the log file to which to write logs for the launched node.
	 * '.log' will be automatically appended to the file name.
	 * If not specified, the nDisplay node's name will be used instead.
	 */

#Loc: <Workspace>/Engine/Plugins/Experimental/LearningAgents/Source/LearningTraining/Private/LearningImitationTrainer.cpp:208

Scope (from outer to inner):

file
namespace    UE::Learning
function     FSharedMemoryImitationTrainer::FSharedMemoryImitationTrainer

Source code excerpt:

		// Start Python Sub-process

		const FString CommandLineArguments = FString::Printf(TEXT("\"%s\" SharedMemory \"%s\""), 
			*FileManager.ConvertToAbsolutePathForExternalAppForRead(*(PythonContentPath / TEXT("train_imitation.py"))),
			*FileManager.ConvertToAbsolutePathForExternalAppForRead(*ConfigPath));

		TrainingProcess = MakeShared<FMonitoredProcess>(
			FileManager.ConvertToAbsolutePathForExternalAppForRead(*PythonExecutablePath),
			CommandLineArguments,
			!(TrainingProcessFlags & ESubprocessFlags::ShowWindow),
			!(TrainingProcessFlags & ESubprocessFlags::NoRedirectOutput));

		if (!(TrainingProcessFlags & ESubprocessFlags::NoRedirectOutput))
		{
			TrainingProcess->OnCanceled().BindRaw(this, &FSharedMemoryImitationTrainer::HandleTrainingProcessCanceled);

#Loc: <Workspace>/Engine/Plugins/Experimental/LearningAgents/Source/LearningTraining/Private/LearningImitationTrainer.cpp:453

Scope (from outer to inner):

file
namespace    UE::Learning
function     FSocketImitationTrainerServerProcess::FSocketImitationTrainerServerProcess

Source code excerpt:


		IFileManager& FileManager = IFileManager::Get();
		const FString CommandLineArguments = FString::Printf(TEXT("\"%s\" Socket \"%s:%i\" \"%s\" \"%s\" %i"),
			*FileManager.ConvertToAbsolutePathForExternalAppForRead(*(PythonContentPath / TEXT("train_imitation.py"))), 
			IpAddress, 
			Port, 
			*FileManager.ConvertToAbsolutePathForExternalAppForRead(*ExtraSitePackagesPath),
			*FileManager.ConvertToAbsolutePathForExternalAppForRead(*IntermediatePath),
			LogSettings == ELogSetting::Normal ? 1 : 0);

#Loc: <Workspace>/Engine/Plugins/Experimental/LearningAgents/Source/LearningTraining/Private/LearningImitationTrainer.cpp:463

Scope (from outer to inner):

file
namespace    UE::Learning
function     FSocketImitationTrainerServerProcess::FSocketImitationTrainerServerProcess

Source code excerpt:

		TrainingProcess = MakeShared<FMonitoredProcess>(
			FileManager.ConvertToAbsolutePathForExternalAppForRead(*PythonExecutablePath),
			CommandLineArguments,
			!(TrainingProcessFlags & ESubprocessFlags::ShowWindow),
			!(TrainingProcessFlags & ESubprocessFlags::NoRedirectOutput));

		if (!(TrainingProcessFlags & ESubprocessFlags::NoRedirectOutput))
		{
			TrainingProcess->OnCanceled().BindRaw(this, &FSocketImitationTrainerServerProcess::HandleTrainingProcessCanceled);

#Loc: <Workspace>/Engine/Plugins/Experimental/LearningAgents/Source/LearningTraining/Private/LearningPPOTrainer.cpp:304

Scope (from outer to inner):

file
namespace    UE::Learning
function     FSharedMemoryPPOTrainer::FSharedMemoryPPOTrainer

Source code excerpt:

			// Start Python Training Sub-process

			const FString CommandLineArguments = FString::Printf(TEXT("\"%s\" SharedMemory \"%s\""), 
				*FileManager.ConvertToAbsolutePathForExternalAppForRead(*(PythonContentPath / TEXT("train_ppo.py"))), 
				*FileManager.ConvertToAbsolutePathForExternalAppForRead(*ConfigPath));

			TrainingProcess = MakeShared<FMonitoredProcess>(
				FileManager.ConvertToAbsolutePathForExternalAppForRead(*PythonExecutablePath),
				CommandLineArguments, 
				!(TrainingProcessFlags & ESubprocessFlags::ShowWindow),
				!(TrainingProcessFlags & ESubprocessFlags::NoRedirectOutput));

			if (!(TrainingProcessFlags & ESubprocessFlags::NoRedirectOutput))
			{
				TrainingProcess->OnCanceled().BindRaw(this, &FSharedMemoryPPOTrainer::HandleTrainingProcessCanceled);

#Loc: <Workspace>/Engine/Plugins/Experimental/LearningAgents/Source/LearningTraining/Private/LearningPPOTrainer.cpp:645

Scope (from outer to inner):

file
namespace    UE::Learning
function     FSocketPPOTrainerServerProcess::FSocketPPOTrainerServerProcess

Source code excerpt:


		IFileManager& FileManager = IFileManager::Get();
		const FString CommandLineArguments = FString::Printf(TEXT("\"%s\" Socket \"%s:%i\" \"%s\" \"%s\" %i"), 
			*FileManager.ConvertToAbsolutePathForExternalAppForRead(*(PythonContentPath / TEXT("train_ppo.py"))), 
			IpAddress, 
			Port, 
			*FileManager.ConvertToAbsolutePathForExternalAppForRead(*ExtraSitePackagesPath),
			*FileManager.ConvertToAbsolutePathForExternalAppForRead(*IntermediatePath), 
			LogSettings == ELogSetting::Normal ? 1 : 0);

#Loc: <Workspace>/Engine/Plugins/Experimental/LearningAgents/Source/LearningTraining/Private/LearningPPOTrainer.cpp:655

Scope (from outer to inner):

file
namespace    UE::Learning
function     FSocketPPOTrainerServerProcess::FSocketPPOTrainerServerProcess

Source code excerpt:

		TrainingProcess = MakeShared<FMonitoredProcess>(
			FileManager.ConvertToAbsolutePathForExternalAppForRead(*PythonExecutablePath),
			CommandLineArguments,
			!(TrainingProcessFlags & ESubprocessFlags::ShowWindow),
			!(TrainingProcessFlags & ESubprocessFlags::NoRedirectOutput));

		if (!(TrainingProcessFlags & ESubprocessFlags::NoRedirectOutput))
		{
			TrainingProcess->OnCanceled().BindRaw(this, &FSocketPPOTrainerServerProcess::HandleTrainingProcessCanceled);

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/EditorBuildUtils.cpp:1023

Scope (from outer to inner):

file
function     bool FEditorBuildUtils::RunWorldPartitionBuilder

Source code excerpt:

	const FText& CancelledText,
	const FText& FailureText,
	const FString& CommandLineArguments
	)
{
	// Ask user to save dirty packages
	if (!FEditorFileUtils::SaveDirtyPackages(/*bPromptUserToSave=*/true, /*bSaveMapPackages=*/true, /*bSaveContentPackages=*/false))
	{
		return false;

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/EditorBuildUtils.cpp:1051

Scope (from outer to inner):

file
function     bool FEditorBuildUtils::RunWorldPartitionBuilder

Source code excerpt:

		ProcessHandle = FPlatformProcess::CreateProc(
			*CurrentExecutableName,
			*CommandLineArguments,
			/*bLaunchedDetached*/true,
			/*bLaunchedHidden*/false,
			/*bLaunchedReallyHidden*/false,
			&ProcessID,
			/*PriorityModifier*/0,
			/*OptionalWorkingDirectory*/nullptr,

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Public/EditorBuildUtils.h:271

Scope (from outer to inner):

file
class        class FEditorBuildUtils

Source code excerpt:

	 * @param CancelledText Message shown to the user after cancelling the task 
	 * @param FailureText Message shown to the user if the process returned an error code
	 * @param CommandLineArguments Arguments passed to the other instance commandline
	 * 
	 * @return True if process completed without returning any error code.  
	 */
	static UNREALED_API bool RunWorldPartitionBuilder(
		const FString& MapToLoad,
		const FText& ProgressText,
		const FText& CancelledText,
		const FText& FailureText,
		const FString& CommandLineArguments
		);
private:

	/**
	 * Private helper method to log an error both to GWarn and to the build's list of accumulated errors
	 *
	 * @param	InErrorMessage			Message to log to GWarn/add to list of errors

#Loc: <Workspace>/Engine/Source/Programs/CrashReportClient/Private/CrashReportClient.cpp:187

Scope (from outer to inner):

file
function     FReply FCrashReportClient::SubmitAndRestart

Source code excerpt:

	{
		// Launcher didn't restart the process so start it ourselves
		const FString CommandLineArguments = FPrimaryCrashProperties::Get()->RestartCommandLine;
		FPlatformProcess::CreateProc(*CrashedAppPath, *CommandLineArguments, true, false, false, NULL, 0, NULL, NULL);
		bIsSuccesfullRestart = true;
	}

	return FReply::Handled();
}

#Loc: <Workspace>/Engine/Source/Programs/UnrealMultiUserServer/Private/UnrealMultiUserServerMain.cpp:14

Scope (from outer to inner):

file
class        class CommandLineArguments
function     CommandLineArguments

Source code excerpt:

{
public:
	CommandLineArguments() : ArgC(0), ArgV(nullptr) {}
	CommandLineArguments(int InArgC, char* InUtf8ArgV[]) { Init(InArgC, InUtf8ArgV); }

	void Init(int InArgC, char* InUtf8ArgV[])
	{
		ArgC = InArgC;
		ArgV = new TCHAR*[ArgC];
		for (int32 a = 0; a < ArgC; a++)

#Loc: <Workspace>/Engine/Source/Programs/UnrealMultiUserServer/Private/UnrealMultiUserServerMain.cpp:29

Scope (from outer to inner):

file
class        class CommandLineArguments
function     ~CommandLineArguments

Source code excerpt:

	}

	~CommandLineArguments()
	{
		for (int32 a = 0; a < ArgC; a++)
		{
			delete[] ArgV[a];
		}
		delete[] ArgV;