我从automator(mac os x 10.6.8中的2.1.1版)(python 2.6.1)的shell脚本调用python脚本时找到了解决方法 . 我的问题是os.system("mkdir foo")在一个(非常具体的)情况下工作,其中subprocess.call("mkdir foo") also makes the directory 然后使automator抛出错误 .
我的automator应用程序的目的是接受拖放到它上面的图像 . automator应用只有一个动作:'运行shell脚本',代码如下:
for f in "$@"
do
python dphoto_pythons/uploader.py $f > dphoto_pythons/auto_output.txt
done
$ f是拖动图像的名称 . ('运行shell脚本'设置为将输入作为参数传递 . )这是奇怪的部分:
在'uploader.py'脚本中,我称之为:
retcode=call("mkdir " + dir_full, shell=True) # THIS CAUSES A ERROR IN AUTOMATOR
print "***DOESN'T GET HERE WHEN RUN IN AUTOMATOR****"
它使目录 . 但是没有进入下一个声明 . 而automator会抛出一个错误对话框(只是说我应该检查我的脚本) .
相比之下,如果我从终端“手动”调用uploader.py:
"python uploader.py someimage.jpg"
它没有任何障碍 . 稍微困惑一下之后,我尝试用os.system替换调用:
os.system("mkdir " + stu_dir_full)
####retcode=call("mkdir " + stu_dir_full, shell=True) # BUG
这适用于automator和终端 . 我有一种感觉,我看起来很明显,因为这是一个奇怪的问题 . 但是我想在任何情况下我都会把它放在那里 . 有什么想法吗?
-Mel
1 回答
你可以使用os.mkdir(stu_dir_full)......
但是你的subprocess.call行的问题可能是subprocess.call期望列表不是字符串 . 试试这个: