从Applescript运行Python脚本时出错

时间:2013-04-20 22:55:23

标签: python shell applescript

为什么这不起作用?

AppleScript的:

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

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>

“”“

错误:

  

告诉当前应用程序执行shell脚本“python&amp; script_path&amp;   hello_world.py“ - &gt;错误”sh:script_path:找不到命令sh:   hello_world.py:找不到命令“number 127 Result:error”sh:   script_path:找不到命令sh:hello_world.py:command not found“   127号

1 个答案:

答案 0 :(得分:2)

&符连接字符串文字和变量替换。像这样:

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

您还需要在hello_world.py之前或$ HOME / Desktop结尾处使用斜杠。上面的例子在hello_world.py之前显示了它。

相关问题