我想打开一个文件并等待下一条指令的执行,直到文件未关闭。我点击了链接如何在 mac OSX 10.8.2 上用 python 打开文件 https://stackoverflow.com/questions/19273210/how-to-open-a-file-on-mac-osx-10-8-2-inpython 但它不起作用。
subprocess.call(['open','-W',FileName])
在文本编辑器中打开文件,但仅当文本编辑器从扩展坞强制退出时才执行下一条语句,即使我关闭了打开的文件。这意味着,它应该仅在文件关闭时执行下一条语句,然后文本编辑器应自动从扩展坞退出。
我也尝试过 Popen 但没有成功
ss=subprocess.Popen("~/Downloads/DeletingDocs.txt",shell=True)
ss.communicate()
请建议一些方法
尝试将其另存为“EditOneAndQuit”,然后执行以下操作:
chmod +x EditOneAndQuit
然后从 Python 启动:
#!/bin/bash
# Start textedit in background
open "$1" &
# Wait till textedit has zero documents open
while true
do
sleep 1
docs=`osascript -e 'tell application "textedit" to get documents'`
if [ -z "$docs" ]; then
# Kill off poor old textedit
osascript -e 'tell application "textedit" to quit'
exit
fi
done
首先从 shell 尝试一下,创建一个文档并编辑它:
ls > fred.txt
./OpenOneAndQuit fred.txt
当您通过单击红色按钮关闭文档时,您应该会看到脚本和文本编辑一起退出。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)