首页 > 其他分享 >nohup nohup: ignoring input

nohup nohup: ignoring input

时间:2024-10-10 21:00:28浏览次数:1  
标签:centos ignoring sleep nohup time print input Recorder

nohup 是一个 Unix 和 Linux 命令,用于运行关闭时不会被终止的进程(即"不挂起"的进程)。当你看到 nohup: ignoring input 这个错误时,通常意味着你尝试使用 nohup 去运行一个需要交互式输入的命令【不是这个原因】。nohup 默认情况下会忽略任何输入,并将标准输入重定向到 /dev/null

解决方法:

  1. 如果你正在运行的命令确实需要交互式输入,你可以将输入重定向到某个文件,或者使用管道(pipe)将输入传递给命令。

  2. 如果你不需要命令的任何输入,确保你运行的命令不要期望任何交互式输入。

例如,如果你的命令是 mycommand < input.txt,而你希望 nohup 运行它,你可以简单地运行 nohup mycommand &,这样 nohup 就不会尝试从标准输入读取数据。如果你的命令需要从文件读取输入,可以使用 cat input.txt | nohup mycommand &

 

test.py
import time

while True:
    #time.sleep(3)
    print("pass ")

 

 

[root@VM-8-12-centos Recorder]# nohup python test.py > tes.txt 2>&1 &
[1] 11046

[root@VM-8-12-centos Recorder]# 
[root@VM-8-12-centos Recorder]# more tes.txt
nohup: ignoring input
pass 
pass 
pass 
pass 
pass 
pass 
pass 

 

import time

while True:
    time.sleep(3)
    print("pass ")

 

[root@VM-8-12-centos Recorder]# 
[root@VM-8-12-centos Recorder]# nohup python test.py > tes.txt 2>&1 &
[1] 13596

[root@VM-8-12-centos Recorder]# 
[root@VM-8-12-centos Recorder]# more tes.txt
nohup: ignoring input
[root@VM-8-12-centos Recorder]# 

 

[root@VM-8-12-centos Recorder]# cat > a.py
# script.py
import time 
print("Running in the background")
time.sleep(10)  # 休眠10秒
print("Finished sleeping")

[root@VM-8-12-centos Recorder]# nohup python a.py > a.txt 2>&1 &
[2] 20380


[root@VM-8-12-centos Recorder]# more a.txt
nohup: ignoring input

 [root@VM-8-12-centos Recorder]# more a.txt
nohup: ignoring input
Running in the background
Finished sleeping

 

time.sleep nohup: ignoring input

解释:

time.sleep 是 Python 中的一个函数,用于暂停程序的执行。nohup 是一个 Unix 命令,用于运行关闭时不会被挂起的(no hang up)程序。

当你在终端中运行一个脚本,并且脚本中有 time.sleep 函数,然后你使用 nohup 运行这个脚本并且重定向输出到一个文件时,你可能会看到 "nohup: ignoring input" 的消息。这是因为 nohup 默认忽略输入,即使是当运行的命令期望输入时。

解决方法:

如果你的脚本需要与用户交互(例如,需要从标准输入接收数据),那么你不应该使用 nohup。如果你的脚本不需要用户交互,那么你可以安全地使用 nohup,这时 "nohup: ignoring input" 的消息不是一个错误。

如果你需要运行一个需要用户交互的脚本,并且希望它在后台运行,可以考虑以下方案:

  1.  使用 screen (https://www.cnblogs.com/emanlee/p/3424635.html) 或 tmux 创建一个会话,在会话中运行你的脚本,然后离开会话。脚本将在后台运行,即使你的终端关闭,它也不会停止。

  2.  如果你只是想要脚本在后台运行,并且不需要与终端会话连接,可以修改你的脚本,让它不使用 time.sleep 来暂停,而是使用一个循环来管理时间间隔,并且使用 nohup 运行脚本,并重定向输入和输出。

例如:

nohup python your_script.py > output.log 2>&1 &

这将在后台运行 your_script.py,将标准输出和标准错误重定向到 output.log 文件,并且忽略输入。

 

 

import time
import threading

while True:
    event = threading.Event()
    print('...部分代码...')
    event.wait(5)
    print('...剩下的代码...')

 

[root@VM-8-12-centos Recorder]# nohup python test.py > tes.txt 2>&1 &
[1] 31788
[root@VM-8-12-centos Recorder]# more tes.txt
nohup: ignoring input

 

 

只有全部  time.sleep  都运行完了,才能开始输出内容到  tes.txt 文件中。

即使把print放到很靠前的位置,把time.sleep 放到最后一行。

如下:

# script.py
import time
 
print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(11)  # 休眠10秒

标签:centos,ignoring,sleep,nohup,time,print,input,Recorder
From: https://www.cnblogs.com/emanlee/p/18456400

相关文章

  • html input file 选择时不显示所有文件*.*
    constpickerOpts={types:[{description:"Images",accept:{"image/*":[".png",".gif",".jpeg",".jpg"],},},],excludeAcceptAllOption:true,multiple:false,};document.getElementById(&......
  • 探究AudioPolicyManager.cpp中的成员变量mAvailableOutputDevices/InputDevices是根据
    2024-09-2310:29:48.792286-445APM-AudioPolicyEnginepid-286Wframeworks/av/services/audiopolicy/enginedefault/src/Engine.cpp:getDeviceForStrategyInt:2782024-09-2310:29:48.792286-445AudioFlingerpid......
  • 解决 PBootCMS 网站迁移后出现的 “No input file specified” 错误
    1.检查 .user.ini 文件进入网站根目录:使用FTP客户端或SSH连接到服务器,进入网站根目录。查找 .user.ini 文件:使用命令 ls-la 查看隐藏文件。sh ls-la删除 .user.ini 文件:如果存在 .user.ini 文件,删除它。sh rm.user.ini2.......
  • PbootCMS网站转移后无法打开报错提示“No input file specifed”
    当你在迁移PBootCMS网站后遇到“Noinputfilespecified”的错误时,这通常是由于配置文件或服务器设置问题导致的。以下是一些详细的排查和解决步骤:排查步骤检查 .user.ini 文件确认根目录下是否存在 .user.ini 文件。如果存在,尝试删除该文件。重启服务器尝......
  • 网站打开提示: No input file specifed.
    当你遇到网站打开时提示“Noinputfilespecified.”的问题时,通常是因为PHP配置文件 .user.ini 导致的。这个问题可以通过以下步骤来解决:解决步骤检查根目录中的 .user.ini 文件删除 .user.ini 文件重启Web服务器验证问题是否解决详细步骤1.检查根目录中的 .use......
  • opencascade AIS_WalkDelta、AIS_ViewInputBuffer源码学习工作
    opencascadeAIS_WalkDelta前言运行方法1.空构造函数。AIS_WalkDelta():myIsDefined(false),myIsJumping(false),myIsCrouching(false),myIsRunning(false){}2.返回平移组件。constAIS_WalkPart&operator[](AIS_WalkTranslationthePart);3.返回平移组件。A......
  • elementUI 的 input无法输入bug解决
    1、出现bug的原因    是因为数据层虽然改变了,但是并没有引起视图层的变化2、解决方案@input="forceUpdate($event)"//在input框上加输入事件forceUpdate(e){this.$forceUpdate()强制刷新}jeecg-boot框架前端写了个筛选组件:SearchBox.vue,测试人员发现输......
  • 05 第六组(10个) sorted enumerate callable id len range open input
    第六组(10个)lenprintinputopen,文件rangepy2:v1=rang(10)#会生成列表[0....9]立即创建v1=xrang(10)#生成对象不会立即创建,只有使用循环时,进行创建,用一个进行创建一个,更节省内存py3:v1=rang(10)#会生成列表[0....9]#生成......
  • el-input只能输入某某格式
    1.只能输入数字<el-inputv-model="rowForm.carriage"@input="value=>rowForm.carriage=Number(value.replace(/[^\d]/g,''))"/>2. 输入数字和小数点@input="rowForm.carriage=rowForm.carriage.replace(/[^\d......
  • 报表中按下上下左右按键input会像excel一样跳转聚焦
    上下左右按键input聚焦###html使用在需要聚焦的input后加下面内容@keydown.native="handleKeyDown($event,0,0)":ref="'0_0'"或者@keydown.native="handleKeyDown($event,index,0)":ref="`${index}_0`"###引入此方法h......