2015-02-23 63 views
1

我想在我的Raspberry Pi启动时运行两个python脚本。从rc.local shell脚本启动丢失文件

如果我 蟒蛇script1.py 蟒蛇script2.py推出他们两个脚本工作

他们还用一个shell脚本工作在含有

python script1.py & 
python script2.py & 

同一文件夹但是,如果我要么添加个别脚本到rc.local启动文件或shell脚本,我会收到丢失文件的错误。

如果我添加了Python脚本通过rc.local中来启动则声称,文本文件,我在脚本中调用缺失:

[email protected] ~ $ sudo service rc.local start 
My IP address is 192.168.0.4 
[email protected] ~ $ 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脚本,然后声称他们错过了。

[email protected] /etc $ sudo service rc.local start 
My IP address is 192.168.0.4 
[email protected] /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 

这是关于权限?我的脚本文件夹是递归的。

所有的文件在那里,脚本直接运行良好。这与通过rc.local启动过程在文件内运行文件有关......但我不知道该怎么做!

非常感谢。

+0

在'rc.local'有着完全不同的环境,然后运行一个脚本:

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

你的第二个问题同样当你从控制台启动它时。对于初学者来说,它将以'root'(而不是你的普通用户)的身份运行,并且它不会从你的普通用户的主目录开始 – 2015-02-23 11:00:42

回答

3

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

'full/path/to/script2.py' 
+0

啊,我很好,但是,我需要“with打开“部分在shell脚本或python内?在Python脚本里面,对吗? – joep1 2015-02-23 11:18:47

+1

@ joep1。是的,在python脚本中。 – 2015-02-23 11:19:31