Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从Applescript运行Shell脚本_Python_Bash_Macos_Shell - Fatal编程技术网

Python 从Applescript运行Shell脚本

Python 从Applescript运行Shell脚本,python,bash,macos,shell,Python,Bash,Macos,Shell,我想在OSX中使用Automator运行一个Shell脚本。shell脚本调用位于文件夹“/Users/Tex/Python”中的Python文件。我的代码是: on run {input, parameters} tell application "Terminal" do shell script "/Users/Tex/anaconda3/bin/python /users/Tex/Python/MoveFiles.py $@" end tell return input

我想在OSX中使用Automator运行一个Shell脚本。shell脚本调用位于文件夹“/Users/Tex/Python”中的Python文件。我的代码是:

on run {input, parameters}

tell application "Terminal"
    do shell script "/Users/Tex/anaconda3/bin/python  /users/Tex/Python/MoveFiles.py $@"
end tell

return input
当我执行automator脚本时,会出现如下错误:

Terminal got an error: /users/Tex/anaconda3/bin/python:
can't open file '/users/Tex//Python/Move_Files.py': [Errno 2] No such file or directory
我怀疑问题在于“/Users/Tex”文件夹位于OSX操作系统的不同驱动器上,但Shell解释器不知道这一点。我曾尝试使用python文件的完整路径,即包括卷名(iMac磁盘A),但其中包含空格这一事实似乎给Shell带来了另一个问题


感谢您对如何使thsi工作的反馈

我看到您所打开的文件与错误消息中的路径之间存在两个差异。是哪一个?还有什么问题吗?在Unix上,在解释路径时,卷是不相关的。如果命令行中的绝对路径是有效的,那么这里应该没有问题。亚历克西斯:是的,我编辑了路径和文件名以减少它们的长度。“Do Shell”行上的文件名不正确,应为“Move_files.py”。恐怕我没有看到输入和错误输出之间的第二个错误。不幸的是,我也不明白你关于路径的第二条评论的要点。你能再解释一下吗。谢谢Unix不是Windows。绝对路径从根开始,当到达驱动器的装载点时,它会透明地下降到驱动器中。打开终端,转到包含脚本的文件夹,然后键入
pwd
,找出要使用的正确路径。Python清楚地告诉您,您为它提供的路径不存在。既然你在问题中伪造了路径,真的没什么好说的了。恕我直言,我认为你错过了我文章的重点。首先,我使用的是osx,而不是Windows。其次,我理解了绝对路径的概念。我不明白的是,为什么Shell没有考虑我认为固有的“别名”,因为它指定了我的主目录(/Users/Tex)位于启动驱动器的不同磁盘上。