1

为什么这不起作用?

苹果脚本:

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 script "python & script_path & hello_world.py" --> error "sh: script_path: command not found sh: hello_world.py: command not found" number 127 结果: error "sh: script_path: command not found sh:hello_world.py:找不到命令“第 127 号

4

1 回答 1

2

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

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

您还需要在 hello_world.py 之前或 $HOME/Desktop 末尾添加一个斜杠。上面的示例在 hello_world.py 之前显示了它。

于 2013-04-21T00:10:31.647 回答