2
\$\begingroup\$

I'm working on a tool that generates some files for Unreal Projects. The only thing is if I try to get it to compile the project through CreateProcess the command doesn't run the same as the command line. I just get an error message from UBT about rule files not existing.

Command being run from CreateProcess:

STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));

CreateProcess("C:/path/to/UnrealBuildTool.exe",
       "ProjectEditor Win64 Development C:/path/to/project.uproject -waitmutex -Deploy",
            NULL,
            NULL,
            FALSE,
            0,
            NULL,
            NULL,
            &si,
            &pi
        );
WaitForSingleObject(pi.hProcess, INFINITE);

CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

In the command line C:\path\to\UnrealBuildTool.exe ProjectEditor Win64 Development C:\path\to\project.uproject -waitmutext -Deploy successfully compiles the project from any directory. Is there any other variables I need to pass into CreateProcess to get this command to run?

EDIT: Adding space to the start of the argument string fixed the issue. Is there any reason why Windows would need that space?

\$\endgroup\$
  • \$\begingroup\$ The code provided won't run because the first argument is not a string and the second argument is using backslashes that result in escape sequence characters rather than slashes. \$\endgroup\$ – Pharap Apr 25 '17 at 7:12
  • \$\begingroup\$ @pharap I updated it so the path and strings are correct in the examples. That's what it is in my actual code. I had to add a space to the start of the argument string for everything to get detected correctly. Is that an issue with Windows or how UBT handles arguments? I have another CreateProcess call for generating project files, but that runs without any issues, whether I place a space at the start or end of the argument. \$\endgroup\$ – ZeroPhase Apr 25 '17 at 7:17
  • \$\begingroup\$ UnrealBuildToot.exe ? \$\endgroup\$ – JonS Apr 26 '17 at 5:49
  • \$\begingroup\$ @JonS That was a typo. I got it working. There's still the issue that I have to add a space to the start of the argument for a compilation to occur. \$\endgroup\$ – ZeroPhase Apr 26 '17 at 10:30
1
\$\begingroup\$

This is happening because you're not actually passing the project ("ProjectEditor") to UnrealBuildTool when you invoke it via CreateProcess, which causes it to not build anything.

The first argument of a Windows command-line should be the name of the process or executable being invoked. CreateProcess does not join the process name you specify to the front of the command-line you specify. You need to do that yourself.

UnrealBuildTool is a C# application. The .NET runtime takes this first space-delimited argument and stores it elsewhere, passing the subsequent arguments to the Main() function of UnrealBuildTool, so the first argument it sees is "Win64." That's why when you add a space in front of your project name, you "fix" it. You've changed it so that the first space-delimited argument is an empty string.

You can verify this by writing a simple C# program that just prints all the arguments supplied to main, and trying to invoke it similarly. Using a tool like Process Explorer would also let you examine the actual command lines for the processes and see how they differ.

A more correct solution would be to call CreateProcess like this:

CreateProcess("C:/path/to/UnrealBuildTool.exe",
              "C:/path/to/UnrealBuildTool.exe ProjectEditor ..etc...",
              ...);
\$\endgroup\$
  • \$\begingroup\$ Alright, so it can be treated similarly to the family of exec functions. \$\endgroup\$ – ZeroPhase Dec 15 '17 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.