rc.local shell 脚本启动缺少文件

Missing file(s) from rc.local shell script startup

我正在尝试 运行 在我的 Raspberry Pi 上启动两个 python 脚本。

如果我用 python script1.py pythonscript2.py

他们还在包含

的同一文件夹中使用shell脚本
python script1.py &
python script2.py &

但是如果我将单独的脚本添加到 rc.local 启动文件或 shell 脚本,我会收到丢失文件的错误。

如果我通过 rc.local 添加 python 脚本启动然后它声称我在脚本中调用的文本文件丢失:

pi@raspberrypi ~ $ sudo service rc.local start
My IP address is 192.168.0.4 
pi@raspberrypi ~ $ Traceback (most recent call last):
  File "home/pi/scripts/script1.py", line 8, in <module>
    scripts.make_batch(randint(10,12))
  File "/home/pi/scripts/functions.py", line 36, in make_batch
    num_lines = sum(1 for line in open('script1_file.txt'))
IOError: [Errno 2] No such file or directory: 'script1_file.txt'
Traceback (most recent call last):
  File "home/pi/scripts/script2.py", line 5, in <module>
    scripts.check(3,30)
  File "/home/pi/scripts/functions.py", line 78, in check
    with open('script2_file.txt', 'r+') as followed:
IOError: [Errno 2] No such file or directory: 'script2_file.txt'
^C

如果我将批处理 script.sh 添加到调用 python 脚本的启动中,然后它声称它们丢失了。

pi@raspberrypi /etc $ sudo service rc.local start
My IP address is 192.168.0.4
pi@raspberrypi /etc $ python: can't open file 'script1.py': [Errno 2] No such file or directory
python: can't open file 'script2.py': [Errno 2] No such file or directory
^C

这与权限有关吗?我的脚本文件夹是755递归。

所有文件都在那里,脚本 运行 没问题。这与 运行 通过 rc.local 启动过程中的文件中的文件有关...但我不知道是什么!

非常感谢帮助。

您需要提供文件的完整路径:

with open('full/path/to/script2_file.txt', 'r+') 

第二个问题也一样:

'full/path/to/script2.py'