shell脚本调用python脚本的路径问题
2013-11-22 18:07
316 查看
脚本的相互调用中,只有在同一级目录下才可以使用__file__参数去获取路径名,(在shell里使用pwd也同样),否则,使用的就是主文件(最开始运行的脚本程序)的所在位置,是错误路径:一定要注意当期那运行主文件是谁
而
/article/8755848.html
[deve_test_user@A3-Tracker-redis-deve script]$ vim testobseve.sh
1 file_path=`dirname $0`
2 echo $file_path
3
4 testfile="$file_path/observereport"
5 python $testfile/test.py
test.py:
import os
import sys
file_path=os.path.dirname(os.path.abspath("__file__"))
print file_path
文件test.py在/home/www/allyes/mifc/mIFC-BE/current/script/observereport
是script的下一级目录
而输出为:
[deve_test_user@A3-Tracker-redis-deve script]$ sh testobseve.sh
.
/home/www/mifc/mIFC-BE/mifc-BE/script
可以看出 只能输出shell脚本的当前目录了
而
shell脚本相互调用时路径也要注意部分命令会使用当前文件路径:参见
shell脚本里面相互调用时路径不要用pwd获取
/article/8755848.html [deve_test_user@A3-Tracker-redis-deve script]$ vim testobseve.sh
1 file_path=`dirname $0`
2 echo $file_path
3
4 testfile="$file_path/observereport"
5 python $testfile/test.py
test.py:
import os
import sys
file_path=os.path.dirname(os.path.abspath("__file__"))
print file_path
文件test.py在/home/www/allyes/mifc/mIFC-BE/current/script/observereport
是script的下一级目录
而输出为:
[deve_test_user@A3-Tracker-redis-deve script]$ sh testobseve.sh
.
/home/www/mifc/mIFC-BE/mifc-BE/script
可以看出 只能输出shell脚本的当前目录了
相关文章推荐
- shell脚本调用python脚本的路径问题
- python的subprocess:子程序调用(调用执行其他命令);获取子程序脚本当前路径问题
- python的subprocess:子程序调用(调用执行其他命令);获取子程序脚本当前路径问题
- shell脚本里面相互调用时路径不要用pwd获取
- python调用shell脚本
- Python for .net脚本调用dotnet框架(ref和out参数问题)
- 【原】Gradle调用shell脚本和python脚本并传参
- shell脚本里面相互调用时路径不要用pwd获取
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)()【转】
- 分享脚本,同一个问题,php,python,shell的写法
- [Shell]crontab 运行任务调用shell脚本,相对路径无法找到
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)【转】
- c语言中调用shell脚本返回值问题分析
- Java之怎么通过java去调用并执行shell脚本以及问题总结(转)
- C#调用Power Shell 管理Office365 执行脚本时遇到的问题
- c语言中调用shell脚本返回值问题分析
- python调用shell脚本
- crontab执行任务调用shell脚本,相对路径无法找到