【问题标题】:How to watch a file and execute multiple commands when changed更改时如何查看文件并执行多个命令
【发布时间】:2021-05-27 13:00:30
【问题描述】:

我在 python 环境中需要这个。示例here on my Github

我有一个文件requirements.in,我想看看它是否有变化。我向其中添加库,保存后将运行编译和安装脚本。

我使用pip-compile 将需求编译到requirements.text 文件中。然后使用 pip 安装此需求文件中的所有内容。理想情况下,我想创建一个也运行 jupyter notebook 的捆绑脚本。

目前我使用了python库“when-changed”并采用了这种方法:

#!/bin/bash


jupyter notebook &
when-changed requirements_dev.in pip-compile requirements_dev.in && requirements_dev.in pip install -r requirements_dev.txt && echo 'Installed requirements'

这种方法的问题是它只编译需求而不安装它或执行echo语句。我猜这是因为when-changedlibrary 只能执行一个命令。

因此我的问题是:如何查看文件并执行多个命令? (不一定是 bash 脚本。也可以是 python 或任何最适合的)

【问题讨论】:

    标签: python bash shell scripting command


    【解决方案1】:

    我想出的一个解决方法是在一个单独的终端窗口中启动 jupyter notebook,而在另一个终端窗口中启动 watcher。然后启动脚本如下所示:

    #!/bin/bash
    
    pip-compile requirements_dev.in && pip install -r requirements_dev.txt && echo 'Installed requirements'
    

    我只是运行

    when-changed requirements_dev.in bash startup.sh
    

    在自己的窗口中。

    不过,我会对其他解决方案保持开放和好奇。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多