python - 尝试运行 Python35 脚本时使用 nohup 吗?

标签 python linux bash putty

我正在尝试使用 putty 控制台在 Linux 服务器上运行 python 程序,从通过 WinSCP 上传到服务器的文件夹中提取程序和包。当我使用命令正常运行程序时:

python35 program.py

它工作正常并开始运行。问题是当我的计算机关闭并且腻子窗口消失时,我需要在服务器上运行该程序。

我读到您可以使用 nohup 命令来执行此操作,但是每当我运行时:

nohup python35 program.py &

它返回:

ignoring input and appending output to `nohup.out'
nohup: failed to run command `python35': No such file or directory

此时程序不会运行,并且会在 WinSCP 上创建一个空的 nohup.out 文件。

为什么会发生这种情况?我该如何修复它?到目前为止,我还没有找到任何等效的错误。

最佳答案

正如上面评论中所确定的,python35 是一个 shell 别名。由于 nohup 在子 shell 中运行给定命令,因此在父 shell 进程中定义的别名将不可用。

使用以下命令:

nohup /opt/rh/rh-python35/root/usr/bin/python program.py &

关于python - 尝试运行 Python35 脚本时使用 nohup 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47016416/

相关文章:

python - 删除 scipy 稀疏矩阵中的 nan 行

python - 访问张量中各个元素的更好方法

linux - 尝试在传递两个参数时调用脚本

linux - Linux终端上后台的正确使用

linux - 在 Bash 脚本中创建日志

python - 试图在两个日期列之间进行区分

linux - 内联 if shell 脚本

xml - 用于更改 xml 元素的 shell 脚本

linux - bash(可能可以使用 perl/python): filter space delimited arg list through regexes

python - 苹果系统; Python3; FileNotFoundError : [Errno 2] No such file or directory: '' . 如何修复?