我想推出一个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
发布评论