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

时间:2015-02-23 10:37:20

标签: python linux bash shell batch-file

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

如果我用它们启动它们,两个脚本都可以工作     python script1.py     python script2.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

如果我将批处理脚本.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启动过程在文件中运行文件有关...但我不知道是什么!

非常感谢。

1 个答案:

答案 0 :(得分:3)

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

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

第二个问题也是如此:

'full/path/to/script2.py'