nohup命令只能在相对目录下工作

2024-05-15 23:22:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过nohup运行python脚本,并调用它的完整路径抛出no such file or directory。你知道吗

示例:

nohup python3 ./script.py

作品

nohup python3 /full/path/to/file/script.py

不起作用。你知道吗

cat nohup.out

Python: can't open file '/full/path/to/file/script.py':
[Errno 2] No such file or directory

如果我给出了完整路径,为什么nohup找不到文件,但是如果我在目录中,为什么找不到?你知道吗


Tags: ortopathnopy路径脚本示例
1条回答
网友
1楼 · 发布于 2024-05-15 23:22:35

它也在绝对路径中工作。下面是一个例子。你知道吗

我通过python脚本打印Linux服务器时间,其中包含绝对路径和相对路径。你知道吗

[root@ip-172-31-11-214 tmp]# pwd
/tmp
[root@ip-172-31-11-214 tmp]# ls -lrth
total 4.0K
-rw-rw-r  1 ec2-user ec2-user 113 Aug  9 20:28 test.py
[root@ip-172-31-11-214 tmp]# nohup python test.py
nohup: ignoring input and appending output to ‘nohup.out’
[root@ip-172-31-11-214 tmp]# cat nohup.out
This line will be printed.
2019-08-09 20:29:37.417722
[root@ip-172-31-11-214 tmp]# cd /root/
[root@ip-172-31-11-214 ~]# pwd
/root
[root@ip-172-31-11-214 ~]# nohup python /tmp/test.py
nohup: ignoring input and appending output to ‘nohup.out’
[root@ip-172-31-11-214 ~]# cat /root/nohup.out
This line will be printed.
2019-08-09 20:30:26.057960
[root@ip-172-31-11-214 ~]#

相关问题 更多 >