.
I have an “as3 windows” project that requires executing the command line by calling “cmd. exe”. I have always wanted to use “openfl” 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 OpenFL?
.
Never did that but if I had to I would try with sys.io.Process - Haxe 4.3.7 API
1 Like
OpenFL provides an implementation of NativeProcess.
1 Like
However, we may not have proper implementations of readMultiByte and writeMultiByte, so you may run into issues there.
1 Like
.
@[Matse]
@[joshtynjala]
.
I’m just checking if ‘Call. as’ is easy to implement in’ openfl ‘. If it’s not easy to implement, I’ll continue using’ air '.
.
