【问题标题】:command works right in python subprocess when run on terminal but failed when execute in crontab命令在终端上运行时在 python 子进程中正常工作,但在 crontab 中执行时失败
【发布时间】:2020-07-14 08:06:28
【问题描述】:

我正在尝试每天从 crontab 启动守夜测试。 当我在 macOS 终端上启动我的 python 脚本时一切正常,但是一旦我通过调用我的 python script 启动 cron 作业。发生以下错误:

"env: node: No such file or directory"

我试图设置 以下是我尝试从 python 子进程运行的命令:

cmd_run =["/usr/local/bin/yarn test /Users/mytest/path/ --tag dbg"]
child_env = os.environ.copy() // inherit shell env setting ? 

with open(full_log, 'w') as fd:
        process=subprocess.Popen(cmd_run, stdout=fd, stderr=fd, shell=True, env=child_env)

我需要运行的实际命令是:

E2E_BASEHOST=https://<myhost> E2E_ENV=bk E2E_TESTS_DIRECTORY=./bk/tests **node**  node_modules/nightwatch/bin/runner.js -c ./node_modules/@bk/e2e-testing-configuration/src/nightwatch.conf.js
--group affiliates/bookings2/tests/src/app/ --tag bsb --retries 2

我猜是因为子进程找不到“节点” 我在终端上运行“哪个节点” 可以在这里找到:

/usr/local/bin/node

那么我在这里缺少什么?

【问题讨论】:

    标签: python-3.x macos cron nightwatch


    【解决方案1】:

    你可以把它放在你的 crontab 中:

    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    

    【讨论】:

      猜你喜欢
      • 2013-12-28
      • 2014-07-06
      • 2014-08-06
      • 1970-01-01
      • 2014-09-05
      • 2018-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多