简体   繁体   English

从命令行运行emacs并处理锁定的文件

[英]Running emacs from the command line and handling locked files

I'm using org-mode and am looking to export my agenda ( example of an agenda ) to a text file so that I can display it with conky. 我正在使用org-mode并希望将我的议程(议程示例 )导出到文本文件中,以便我可以用conky显示它。 The org-mode manual features this command line example to do this: 组织模式手册使用此命令行示例来执行此操作:

emacs -batch -l ~/.emacs -eval '(org-batch-agenda "t")' | lpr

I've modified this like so: 我这样修改过:

emacs -batch -l ~/.emacs -eval '(org-batch-agenda "e")' \
> ~/org/aux/agenda-export.txt

I have this set as a cron job to run every 5 minutes. 我把这套作为一个每5分钟运行一次的cron工作。 It works great unless I actually have emacs open. 除非我真的打开emacs,否则它的效果很好。 Then I noticed that the file agenda-export.txt was empty. 然后我注意到文件agenda-export.txt是空的。 In running this manually from the coammand line vs. through cron, I get this error (or similar depending on the files I have open): 在从coammand行与通过cron手动运行时,我收到此错误(或类似取决于我打开的文件):

...~/org/file.org locked by jwhendy (pid 10935): (s, q, p, ?)?

I was going to write a script to perhaps export to agenda-export-test.txt , then perhaps check for an empty file or no lines ( wc -l == 0 maybe?). 我打算编写一个脚本,可能导出到agenda-export-test.txt ,然后检查一个空文件或没有行( wc -l == 0可能?)。 If true, leave the existing file alone and delete agenda-export-test.txt . 如果为true,则保留现有文件并删除agenda-export-test.txt If not, then move agenda-export-test.txt to agenda-export.txt . 如果没有,则将agenda-export-test.txt移动到agenda-export.txt

But... when I try to run such a script, I'm met with the same emacs inquiry about whether to steal the lock, proceed, or quit. 但是......当我尝试运行这样的脚本时,我遇到了关于是否窃取锁定,继续或退出的相同emacs询问。 I'm fine with proceeding, as I don't think org-agenda does anything to the files and thus it wouldn't harm anything... but I don't know how to tell emacs to "force" or choose "proceed" if problems are encountered. 我很好继续,因为我不认为组织议程对文件做任何事情因此它不会伤害任何东西......但我不知道如何告诉emacs“强制”或选择“继续“如果遇到问题。 I need something non-interactive. 我需要一些非互动的东西。

So, to summarize, my thoughts were to try: 总而言之,我的想法是尝试:

  • passing a --force option or similar to emacs to make it proceed at the pause 传递--force选项或类似于emacs以使其在暂停时继续
  • see if the exported tmp file has any lines and deal with it accordingly 查看导出的tmp文件是否有任何行并相应地处理它
  • tell emacs to run in "read only mode" (but I don't think it exists) 告诉emacs以“只读模式”运行(但我认为它不存在)

The main issue is that with cron, I'm not there to tell the process what to do, and so it just just make an empty file as the exported results. 主要的问题是,使用cron,我不是要告诉进程该做什么,所以它只是将一个空文件作为导出的结果。 How can I handle this locked file business with a "blind" process like cron that can't respond? 如何通过像cron这样无法响应的“盲目”进程来处理这个锁定的文件业务?

I've tried asking the mailing list as well without a working outcome. 我也尝试过询问邮件列表而没有工作结果。 [1] I wondered if someone here might have ideas. [1]我想知道这里的某人是否有想法。

[1] http://www.mail-archive.com/emacs-orgmode@gnu.org/msg45056.html [1] http://www.mail-archive.com/emacs-orgmode@gnu.org/msg45056.html

Have you tried copying file without using emacs? 您是否尝试过不使用emacs复制文件? put in your crontab: 放入你的crontab:

cp ~/org/file.org /tmp/export.org && emacs -batch .... /tmp/export.org ..

A regular "cp" command should not copy emacs locks. 常规的“cp”命令不应该复制emacs锁。 Of course, once in a while you might get a damaged file if you save agenda just during cp command, but this should not be too bad. 当然,如果你在cp命令期间保存议程,你可能偶尔会得到一个损坏的文件,但这不应该太糟糕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM