简体   繁体   English

从Applescript运行Python脚本时出错

[英]Error running Python script from Applescript

Why doesn't this work? 为什么不起作用?

Applescript: AppleScript的:

set script_path to "$HOME/Desktop"
do shell script "python & script_path & hello_world.py"

Python script: Python脚本:

#!/usr/bin/env python
print "Content-Type: text/html"
print
print """\
<html>
 <head>
  <title>Python - Hello World</title>
 </head>
 <body>
  Hello World
 </body>
</html>

""" “””

Errors: 错误:

tell current application do shell script "python & script_path & hello_world.py" --> error "sh: script_path: command not found sh: hello_world.py: command not found" number 127 Result: error "sh: script_path: command not found sh: hello_world.py: command not found" number 127 告诉当前应用程序执行shell脚本“ python&script_path&hello_world.py”->错误“ sh:找不到脚本命令sh:hello_world.py:找不到命令”编号127结果:错误“ sh:script_path:找不到命令” sh:hello_world.py:找不到命令“编号127

The ampersands concatenate the string literals and variable substitutions. “与”号连接字符串文字和变量替换。 Like so: 像这样:

set script_path to "$HOME/Desktop"
do shell script "python " & script_path & "/hello_world.py"

You also need a slash before hello_world.py or at the end of $HOME/Desktop. 您还需要在hello_world.py之前或$ HOME / Desktop末尾添加一个斜杠。 The example above shows it before hello_world.py. 上面的示例在hello_world.py之前显示了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM