Can ‘openfl windows’ use’ cmd. exe 'to execute various cmd bat command line instructions?
I have an “as3 air windows” tool that calls “cmd. exe” to execute the “cmd bat” batch command? Can OpenFL be implemented?
.
Call.as
.
package
{
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);
public static function call(e:String,f:String="gbk")
{
process.standardInput.writeMultiByte(e,f);
}
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
{
}
}
}
Call.open(“taskkill /f /im Meteor.exe”);
Call.call(“mkdir pmodel \n”);
Call.call(“mkdir " + pmodelTemp + " \n”);
Call.call(“mkdir " + ptextureTemp + " \n”);
var s0:String = rar + " x -y -o+ pmodelLibrary\ptexture.rar " + pf + " " + ptextureTemp + " \n";
var s1:String = rar + " x -y -o+ pmodelLibrary\pmodel.rar";
var s2:String = " p" + c1 + “.amb”;
var s3:String = " P" + c1 + “.bnc”;
var s4:String = " P" + c1 + “.POS”;
var s5:String = " p" + c1 + “.skc”;
var s6:String = " p" + c1 + "_300.skc";
var s7:String = " p" + c1 + "_800.skc ";
var s8:String = pmodelTemp + " \n";
Call.call(s0 + s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8);
tid1 = setTimeout(function()
{
mb.y = -1000;
s0 = rar + " a -ep1 -apptexture ptexture.pak" + " pmodelLibrary\\ptextureTemp" + "\\*.* \n";
s1 = "move /y " + pmodelTemp + "\\p" + c1 + ".amb pmodel\\p" + c2 + ".amb \n";
s2 = "move /y " + pmodelTemp + "\\p" + c1 + ".bnc pmodel\\P" + c2 + ".bnc \n";
s3 = "move /y " + pmodelTemp + "\\p" + c1 + ".POS pmodel\\P" + c2 + ".POS \n";
s4 = "move /y " + pmodelTemp + "\\p" + c1 + ".skc pmodel\\p" + c2 + ".skc \n";
s5 = "move /y " + pmodelTemp + "\\p" + c1 + "_300.skc pmodel\\p" + c2 + "_300.skc \n";
s6 = "move /y " + pmodelTemp + "\\p" + c1 + "_800.skc pmodel\\p" + c2 + "_800.skc \n";
Call.call(s0 + s1 + s2 + s3 + s4 + s5 + s6);
Call.open(“start Meteor.exe”);
In the past, I’ve used Haxe’s sys.io.Process
to run external processes.
Pretty sure yes. On Linux I’ve built a frontend for MAME that I still use in order to have all the games regrouped inside a single list and a clean and downright simple UI controllable with mouse/keyboard/joysticks,that includes games that aren’t arcade (consoles and such), with a kiosk mode also picking games randomly and running them for a period of time, then quit then launch another, etc…
All game launches are done through generic command lines retrieved from a .xml file and passed to MAME, according to the system family the game is related to… I guess you get the idea. In the early version I used sys.io.Process as @Bink mentioned, but if memory serves (that was 3 or 4 years ago, I’m looking again at the source right now) I switched for a different approach because Process() wasn’t blocking the whole haxe program execution while command was processed and that was annoying because I wanted my program to “freeze” while playing games, for obvious reasons,.. So I switched to Sys.command() instead Sys - Haxe 4.3.7 API
“The current process will block until the command terminates… Use the sys.io.Process
API for more complex tasks, such as background processes, or providing input to the command.”
There’s no reason this shouldn’t work pretty much the same on Windows. For handling path I used haxe.io.Path; haxe.io.Path - Haxe 4.3.7 API