Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Documentation for xProcess

A topic by xijnim created Apr 28, 2024 Views: 1,186 Replies: 6
Viewing posts 1 to 4

Please, i cant find anything about how to use it :(

Developer

for starters, most basic usage is covered here:

http://gamemaker.info/en/manual#execute_program

execute_program(prog,arg,wait) Executes program prog with arguments arg. wait indicates whether to wait for finishing.
execute_shell(prog,arg) Executes the program (or file) in the shell.

Note in order to open a file with execute_shell you will need to specify as a first command line parameter in the prog argument the desired executable to open the file with passed in the arg argument. arg can contain multiple arguments, and they are space separated, so if you want to use a file path, flag, or paremeter with spaces in it, enclose it within single or double quotes (within the initial quotes representing it as a string).

Here's an example:

execute_shell(@'cmd', @'"' + working_directory + @'batch_file.bat"');

or if you need the wait argument to make the call synchronous, use execute_program() instead, like so:

execute_program(@'cmd', @'"' + working_directory + @'batch_file.bat"', true);


if the prog argument in execute_shell or execute_program is command prompt (cmd.exe, cmd, or the absolute path to it, even) it will automatically have /c passed to it so the hidden command prompt window automatically closes when the batch_file.bat is done its execution.

I have documentation for (most) of the C++ library this extension is based on, however the C++ function implementations are rather different from the GameMaker implementation, function names, arguments, and usage are slightly different, but should help point you in the right direction:


https://github.com/time-killer-games/xproc/blob/main/README.md

It's on my to-do list to write documentation for the GameMaker-specific implementation. I've been requested this a lot so i will try to make it a priority soon.

Developer (1 edit)

I just completed writing documentation just now for the GameMaker version of the library:

https://github.com/time-killer-games/libxprocess/blob/main/README.md

Please contact me on discord if you have more questions or need one-on-one assistance.

My discord handle is: samuelvenable

This link is broken, did you delete all your accounts or something?

Developer

the documentation is now included with the extension download itself, look under the extensions folder of the demo project, there should be a libxprocess.zip file, and in there is a ReadMe.md file, if I remember correctly.

(1 edit)

I guess I don't totally understand... I'm trying to run a command to launch a python script, and it compiles, but never runs. What am I doing wrong?

execute_shell(@'python3', @'~/Documents/.../download.py');

for reference, the "download.py" is a scraping script.

**EDIT**

I figured out where I was wrong. I had to specify the install location of python. I would like to know how to perform other actions in the gml script after a script is finished executing. 

Developer (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