I have an “as3 windows” project that requires executing the command line by calling “cmd. exe”. I have always wanted to use “haxe” for development, but I don’t know how to implement this class yet

.

I have an “as3 windows” project that requires executing the command line by calling “cmd. exe”. I have always wanted to use “haxe” for development, but I don’t know how to implement this class yet

.

In AS3, I executed it this way
.
//Open an ‘exe’ program
Call.open(“start Meteor.exe”);
.
//Use ‘cmd. exe’ to execute the command line and close the exe program.
Call.open(“taskkill /f /im Meteor.exe”);
.
//Open “cmd. exe” and add files to the compressed file using “winrar. exe”, as well as copy the files.
Call.skin(“zhiyayouxiData\ptexture\”+Object(root).id1+“\.”);
Call.copy(“zhiyayouxiData\pmodel\”+Object(root).id1+“.amb”,“pmodel\”+Object(root).id2+“.amb”);
.
I have written all of these, mainly the implementation of the “Call. as” class
I don’t know how to implement it in ‘openfl’? Who can help me?
.

“Call.as”

.

package code
{
import flash.filesystem.;
import flash.desktop.
;
import flash.utils.;
import flash.events.
;

public class Call
{
	private static var process: NativeProcess;
	private static var nativeProcessStartupInfo: NativeProcessStartupInfo;

	private static function newexe(EXEPath: String, parentDirectory: String = "", inistr: String = "")
	{
		nativeProcessStartupInfo = new NativeProcessStartupInfo();
		var fileexe: File = File.applicationDirectory.resolvePath(EXEPath); //bin/ffmpeg.exe
		process = new NativeProcess();
		process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, input);
		process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
		process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);

		process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
		process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
		process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);

		if(fileexe.exists)
		{
			nativeProcessStartupInfo.executable = fileexe;
			if(parentDirectory == "")
			{
				nativeProcessStartupInfo.workingDirectory = fileexe.parent;
			}
			else
			{
				nativeProcessStartupInfo.workingDirectory = new File(parentDirectory);
			}
		}
		if(inistr != "")
		{
			var processArgs: Vector. < String > = new Vector. < String > ();
			var s: Array = inistr.split(" ");
			for(var i = 0; i < s.length; i++)
			{
				processArgs.push(s[i]);
			}
			nativeProcessStartupInfo.arguments = processArgs;
			process.start(nativeProcessStartupInfo);
		}
		else
		{
			process.start(nativeProcessStartupInfo);
		}
	}
	newexe("C:/Windows/System32/cmd.exe", File.applicationDirectory.nativePath);

	private static function call(e: String, f: String = "gbk")
	{
		process.standardInput.writeMultiByte(e, f);
	}
	public static function skin(e: String)
	{
		call("zhiyayouxiData\\WinRAR\\WinRAR.exe a -ep1 -apptexture ptexture.pak" + " " + e + "\n");
	}
	public static function copy(file1: String, file2: String)
	{
		call("copy" + " " + file1 + " " + file2 + "/y" + "\n");
	}
	public static function open(e: String)
	{
		call(e + "\n");
	}
	private static function input(e)
	{
		trace("成功发送数据");
	}
	private static function onOutputData(event: ProgressEvent): void
	{
		var jqm = process.standardOutput.readMultiByte(process.standardOutput.bytesAvailable, "GBK");
		trace("输出的数据:", jqm);
	}
	private static function onErrorData(event: ProgressEvent): void
	{
		var jqm = process.standardOutput.readMultiByte(process.standardOutput.bytesAvailable, "GBK");
		trace("出错的信息是:" + jqm);
	}
	private static function onExit(e): void
	{
		trace("调用的exe关闭了");
	}
	private static function onIOError(event: IOErrorEvent): void
	{}
}

}

.

.
Has anyone done a similar project before?
.
How to implement the as class above in haxe?
.

You have Sys.command() to initiate simple processes that you don’t need the result or output of.

Then you have the sys.io.Process class with much more control over the spawned processes (kill, close, exit code, stdin, stdout, etc.)

Finally OpenFL not so long ago introduced the NativeProcess implementation which I believe is a 1:1 representation of the ActionScript version, so the transition should be straightforward and painless.

1 Like

.

Thank you for your response

.

First of all, I’m sorry because I don’t know English and they are all software translations, so there may be some differences

.