如何使用Flash Air的标准输出?

How to use the standard output by Flash Air?

我想用Flash Air做一个命令行工具,但是没有api的AS3可以把内容输出到标准输出。

然后,我尝试使用ANE来解决我的问题(通过制作一个windows ane并使用C的printf函数输出内容),但它不起作用。

有什么方法可以使用Flash air的标准输出,或者Flash Air制作一个命令行工具吗?

c++编写的dll代码为:

FREObject add(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{
    int32_t x,y;
    FREGetObjectAsInt32(argv[0], &x);
    FREGetObjectAsInt32(argv[1], &y);


    int32_t result = x + y;
    FREObject resObj;
    FRENewObjectFromInt32(result, &resObj);

    //I want to use the "printf" to print content to the console
    printf("print by dll: the result is %d\n", result);

    return resObj;
}

but there is not any api of AS3 to output content to standard output.

只有 运行ning OS 进程可以提供 back 标准输出(在 C 中也称为 stdio)。

您能做的最好的事情就是创建一个看起来像命令行工具但实际上它只是 运行s & 将数据传递给实际(本机)OS 命令行工具的应用程序。这意味着在您的工具中,您将用户命令捕获到一个字符串,然后 运行 一个 nativeProcess 涉及该(解析的)字符串作为您的过程参数。

您的应用用户类型示例:calc。您的 AIR 运行s:c:\Windows\System32\calc.exe

无论如何,关于你真正的问题...

I try to use C's printf function to output content, but it doesn't work.

如果你的意思是你用 C 做了一些 test.exe 并且当你得到 AIR 到 运行 它你想捕获 printf输出然后你可以试试:

process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, CTest_OutputData);


process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, CTest_ErrorData);

要捕获输出(它将以字节形式发送),请确保您已创建一些 public byteArrayString。这是 STANDARD_ERROR_DATA 的示例(输出也可能出现在这里,因为您声称 STANDARD_OUTPUT_DATA 不工作)。

无论您选择哪种类型的 progressEvent,该函数中下面显示的代码都可以正常工作。只需输入 "right" 一个。 temp_BA 是您之前设置的 byteArray 变量。

public function CTest_ErrorData (event:ProgressEvent):void
{
    process.standardOutput.readBytes( temp_BA, temp_BA.length, process.standardOutput.bytesAvailable );

    if ( temp_BA.length > 0 )
    {
        temp_String = temp_BA.readUTFBytes(temp_BA.length);
        trace( "temp_String is : " + temp_String ); //if you want to check it
    }

}

最终提示: 您可以通过禁用 "desktop" 并保持 "extended desktop" 勾选来在 Flash IDE 中获取跟踪。稍后安装应用程序时必须勾选两者。