Alex
Alex

Reputation: 21

Haxe - Adding an event to process exit?

Haxe porgramming beginner here and I can't seem to find a solution for my problem.

I'm simply running another program on the computer via sys.io.Process.

import sys.io.Process;
import neko.Lib;

class Main 
{
    static function main() 
    {

        var cProcess = new Process(pClient + sArgs);
    }

}

I only want my Haxe program to be running as long as the "cProcess" exists. So I need some kind of Eventhandler that calls a function when the cProcess is being closed.

Does anyone have an idea how to solve this problem? Any suggestions welcome!

Thanks!

Upvotes: 2

Views: 233

Answers (2)

KevinResoL
KevinResoL

Reputation: 982

Mihail's solution is simple and should work.

If you need more on that, you can try asys, which is the asynchronous version of the sys package in Haxe standard library.

var process = new asys.io.Process('your command');
process.exitCode().handle(function(code) trace('process exited with code: $code'));

It also depends on the platform you are running on. If you are running on platforms with async io like nodejs, things should be simple. Otherwise you have to consider threads.

Upvotes: 1

Mihail Ignatiev
Mihail Ignatiev

Reputation: 853

If all you want to do is wait for the process to complete it's execution just call exitCode(), it will block until launched process exits.

var cProcess = new Process(pClient + sArgs);
cProcess.exitCode();
trace("Done!");

Upvotes: 2

Related Questions