2013-01-03 57 views
2

作爲標題,我可以使用什麼命令/類?並且如果該函數是否存在,是否從commandhell中獲取回調函數?Usinc命令Promt/Shell in Action腳本3

+0

您可以使用Socket連接與cmd.exe進行通信。所以如果你想和CMD溝通,你必須做一個c/C++/visual-C++項目,它調用你需求的所有cmd/shell的操作,後面你可以和這個項目的可執行文件進行通信,當你的項目有結果時將ao/p返回到套接字連接。在其Documentaion中查看關於Socket的更多信息=> http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html –

回答

2

根據this article,您可以運行並與AIR中的其他進程通信。

因此,如果您想運行Windows命令提示符,則必須提供cmd.exe的位置,即「%windir%\ system32 \ cmd.exe」。不幸的是,AIR不會理解%windir%,因此您必須實際提供Windows目錄的完整路徑(通常是C:但您必須弄清楚如何處理不是C的情況)。令人煩惱的是,命令提示符似乎並不像正常的輸入流;嘗試寫入時收到錯誤。可能有一些我不知道的東西。相反,你可以用你的參數來啓動命令提示符。例如,下面的代碼將啓動一個命令提示符(假設Windows在C上),打印「hello」並跟蹤輸出(在本例中,它將只是「hello」)。

var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo(); 
var file:File = File.applicationDirectory.resolvePath("C:\\Windows\\System32\\cmd.exe"); 
nativeProcessStartupInfo.executable = file; 
var processArgs:Vector.<String> = new Vector.<String>(); 
processArgs.push("/C echo 'hello'"); 
nativeProcessStartupInfo.arguments = processArgs; 
process = new NativeProcess(); 
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData); 
process.start(nativeProcessStartupInfo); 

public function onOutputData(event:ProgressEvent):void 
{ 
    trace("Got: ", NativeProcess(event.target).standardOutput.readUTFBytes(process.standardOutput.bytesAvailable)); 
}