Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(6 edits)

Everything you need to know about this is in the demo project, including documentation as previously pointed out in this topic.

These two events in particular are useful for what you need:

Key Press - R Event:

input = GetString("Enter a command to execute from the shell below:", "ENTER COMMAND LINE HERE");

pid = ProcessExecuteAsync(input);

Step Event:

if (pid != 0 && CompletionStatusFromExecutedProcess(pid)) {

  output = ExecutedProcessReadFromStandardOutput(pid);

  if (string_replace_all(string_replace_all(output, "\n", ""), "\r", "") != "") {

    ShowMessage("Process Output:\n\n" + output);

  }

  FreeExecutedProcessStandardOutput(pid);

  FreeExecutedProcessStandardInput(pid);

  pid = 0;

}

Details on Above Code:

The return value of ProcessExecuteAsync() is a Process ID, an ID representing the command run, which can be passed to other functions such as CompletionStatusFromExecutedProcess() and ExecutedProcessReadFromStandardOutput(). If ProcessExecuteAsync() returned zero, the function failed. To check if the function both succeeded and the command completed execution, see if the return value of ProcessExecuteAsync() does not equal zero, and also pass the return value of ProcessExecuteAsync() to CompletionStatusFromExecutedProcess(), while checking if CompletionStatusFromExecutedProcess() returned true to verify the process completed execution, like the above code does. 

You can pass the return value of ProcessExecuteAsync() to ExecutedProcessReadFromStandardOutput() get the Standard Output and Standard Error strings of your python script (both those strings will be combined into one unless you redirect one of them to a file or null device). 

Whenever running ProcessExecuteAsync() or ProcessExecute(), never forget to free memory when the process has completed execution. This can be done by passing the return value of those functions to FreeExecutedProcessStandardOutput() and FreeExecutedProcessStandardInput().

The command argument of ProcessExecuteAsync() and ProcessExecute() treats spaces as separate command line arguments, unless the spaces have quotes around them. Since the command argument has quotes around it already, because it is a string, you will need to use quotes within quotes and apply character escaping on the inner quotes, so the command will recognize the spaces properly and so it won't treat the spaces as separate command line arguments, (for example, working_directory and other paths may contain spaces in them).

Also, ProcessExecute() automatically will wait for the python script to complete its execution before returning to the main game loop. Maybe it would be simpler to use that instead of ProcessExecuteAsync() and having to manually check for completion with Process ID != zero && CompletionStatusFromExecutedProcess() == true.

Lastly:

Please contact me on Discord for quicker help, as we can chat on there in real-time and I'm far more active over there. My discord handle is: samuelvenable