【问题标题】:"Command not found" when using python for shell scripting使用 python 编写 shell 脚本时出现“找不到命令”
【发布时间】:2014-08-16 12:01:50
【问题描述】:

我有这个 python 脚本:

#!/usr/bin/python

print 'hi'

我正在尝试将此脚本作为要在计算集群上执行的作业发送。我用qsub 发送它,如下所示:qsub myscript.py

在运行它之前,我执行了以下操作:

chmod +x myscript.py

但是,当我打开输出文件时,我发现:

Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.

当我打开错误文件时,我发现:

print: Command not found.

那怎么了?!

编辑:我按照this question中的说明进行操作

【问题讨论】:

    标签: python shell sungridengine


    【解决方案1】:

    看起来qsub 没有读取您的shebang 行,所以只是使用shell 执行您的脚本。

    此答案提供了一些关于如何处理此问题的选项,具体取决于您的系统:How can I use qsub with Python from the command line?

    【讨论】:

    • 这个想法是我想避免编写 bash 脚本文件
    【解决方案2】:

    一个选项是将解释器设置为 python,如下所示:

    qsub -S /usr/bin/python  myscript.py
    

    我很确定有另一种方法可以在没有-S 选项的情况下执行此操作,并让 SGE 基于 shebang 中的解释器执行代码;但是,此解决方案可能足以满足您的需求。

    另外,关于这个输出:

    Warning: no access to tty (Bad file descriptor).
    Thus no job control in this shell.
    

    忽略这一点似乎是安全的:

    http://www.linuxquestions.org/questions/linux-software-2/warning-no-access-to-tty-bad-file-descriptor-702671/

    编辑:

    同样有效:

    qsub <<< "./myscript.py"
    qsub <<< "python ./myscript.py"
    

    【讨论】:

      猜你喜欢
      • 2012-06-28
      • 2013-04-26
      • 1970-01-01
      • 2021-01-24
      • 2022-08-17
      • 2016-10-07
      • 2012-08-30
      • 2017-08-15
      • 2020-07-25
      相关资源
      最近更新 更多