的Adobe AIR2的NativeProcess API的JavaScript

编程入门 行业动态 更新时间:2024-10-25 12:27:35
本文介绍了的Adobe AIR2的NativeProcess API的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想推出一个python脚本在Javascript中的NativeProcess API。 在的Adobe AIR API参考针对HTML开发我发现了一个很好的例子,该任务,但它不工作。我抬头吨的其他例子,但仍无法找到答案。

I am trying to launch a python script with the NativeProcess API from Javascript. On the Adobe AIR API Reference for HTML Developers I found a good example for that task, but it does not work. I looked up tons of other examples but still can not find the answer.

下面是例子code HTML文件:

Here is the example code for the html file:

<html> <head> <title>Test</title> <script type="text/javascript" src="AIRAliases.js"></script> <script type="text/javascript"> var process; function launchProcess() { if(air.NativeProcess.isSupported) { air.trace("NativeProcess supported."); setupAndLaunch(); } else { air.trace("NativeProcess not supported."); } } function setupAndLaunch() { var nativeProcessStartupInfo = new air.NativeProcessStartupInfo(); var file = air.File.applicationDirectory.resolvePath("test.py"); nativeProcessStartupInfo.executable = file; var processArgs = new air.Vector["<String>"](); processArgs.push("foo"); nativeProcessStartupInfo.arguments = processArgs; process = new air.NativeProcess(); process.start(nativeProcessStartupInfo); process.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData); process.addEventListener(air.ProgressEvent.STANDARD_ERROR_DATA, onErrorData); process.addEventListener(air.NativeProcessExitEvent.EXIT, onExit); process.addEventListener(air.IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError); process.addEventListener(air.IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError); } function onOutputData() { air.trace("Got: ", process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable)); } function onErrorData(event) { air.trace("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable)); } function onExit(event) { air.trace("Process exited with ", event.exitCode); } function onIOError(event) { air.trace(event.toString()); } </script> </head> <body onload="launchProcess()"> </body> </html>

和这里的code为Python文件(它不工作):

And here the code for the python file (it does not work):

#! /usr/bin/env python2.5 # -*- coding: utf-8 -*- import sys for word in sys.argv: #echo the command line arguments print word print "HI FROM PYTHON" print "Enter user name" line = sys.stdin.readline() sys.stdout.write("hello," + line)

用命令运行AIR应用程序ADL的main.xml 显示我的终端(我用OSX)只的NativeProcess支持。

Running the Air App with the command adl main.xml shows in my terminal (I use OSX) only "NativeProcess supported."

感谢您的帮助。

在这里,我没有给Python文件的修改得到它的工作:

And here the changes I did to the python file to get it working:

#! /usr/bin/env python2.5 # -*- coding: utf-8 -*- import sys import os def convert(args): path = os.path.expanduser('~') + "/Desktop/" myFile = open(path+args, 'w') myFile.write('Hello World\n') myFile.close() sys.stdout.write("Python Done") if __name__ == "__main__": convert(sys.argv[1])

由于pyfunc ...

Thanks to pyfunc...

推荐答案

如果您运行的程序,然后下面是输出:

If you run your program, then following is the output:

test.py HI FROM PYTHON Enter user name

那是这片蟒蛇code正在寻找标准输入和写入标准输出。 我不认为这是可能的,如果你不运行,从外壳。

Thats is this piece of python code is looking for standard input and writing to standard output. I don't think that would be possible if you do not run that from shell.

如何删除:

line = sys.stdin.readline() sys.stdout.write("hello," + line)

和做一些无关痛痒的蟒蛇EX pressions像

and do some innocuous python expressions like

a = 1+4

和看到的,是否可行。我有一种预感,这可能是一个问题。

and see, if that works. I have a hunch that this might be an issue.

更多推荐

的Adobe AIR2的NativeProcess API的JavaScript

本文发布于:2023-11-23 14:16:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621739.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Adobe   NativeProcess   JavaScript   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!