从Actionscript调用python

1 python actionscript actionscript-3

我有一个调用python脚本的Adobe Air程序.我不认为actionscript 3.0正在拨打正确的电话.码:

        var file:File;
        var args:Vector.<String> = new Vector.<String>;

            file = new File().resolvePath("/usr/bin/python");

            var pyScript:File;
            pyScript = File.applicationDirectory.resolvePath("python/mac/merge.py");

            var tempOutPath:String = File.applicationStorageDirectory.resolvePath("out.pdf").nativePath;
            args.push(pyScript.nativePath, "-w", "-o", tempOutPath, "-i");

            for(var x:int; x < numFilesToProcess; x++){

                var pdfPath:String = File(pdfs.getItemAt(x)).nativePath;

                args.push(pdfPath);

            }

            callNative(file, args);
Run Code Online (Sandbox Code Playgroud)

在终端(Mac)中,以下工作正常:

python merge.py -w -o out.pdf -i file1.pdf file2.pdf
Run Code Online (Sandbox Code Playgroud)

args.push(pyScript.native ....行是有问题的.我很感激一些帮助.

meo*_*ouw 6

我使用Air遇到了类似的问题.我需要从Air应用程序打印到收据打印机.我无法从应用程序本身做到这一点所以我使用python RPC服务器为我做的工作,并通过http与它交谈.下面是一个简化版本,为您提供一个想法:

python RPC服务器

from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler

class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/','/RPC2')

server = SimpleXMLRPCServer(('localhost', 8123), requestHandler=RequestHandler)

def myService( arg0, arg1 ):
    #do the stuff
    return 0

server.register_function(myService)
server.serve_forever()
Run Code Online (Sandbox Code Playgroud)

在Air中,我将调用创建为XML字符串并发出请求.我没有显示所有细节,因为我使用的是javascript而不是actionscript,所以请将其视为伪代码.

// XML as a string
// possibly create the XML and toXMLString() it?
var data:String = '
<?xml version="1.0"?>
<methodCall>
    <methodName>myService</methodName>
    <params>
        <param>
            <string>file1.pdf</string>
        </param>
        <param>
            <string>file2.pdf</string>
        </param>
    </params>
</methodCall>';

var req:URLRequest = new URLRequest('localhost:8123');
rec.method = 'POST';
rec.data = data;
var loader:URLLoader = new URLLoader( req );
//etc
Run Code Online (Sandbox Code Playgroud)