zoukankan      html  css  js  c++  java
  • shell脚本调用python脚本的路径问题

    脚本的相互调用中,只有在同一级目录下才可以使用__file__参数去获取路径名,(在shell里使用pwd也同样),否则,使用的就是主文件(最开始运行的脚本程序)的所在位置,是错误路径:一定要注意当期那运行主文件是谁

    shell脚本相互调用时路径也要注意部分命令会使用当前文件路径:参见

    shell脚本里面相互调用时路径不要用pwd获取

    http://blog.csdn.net/longshenlmj/article/details/16887505 

    [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脚本的当前目录了

  • 相关阅读:
    Redis内存回收策略
    7、IMS
    6、端局、汇接局、关口局、长途局
    5、IMS网元
    4、IMS
    3、NAT
    2、SIP
    1、B2BUA
    九、数据库——sql server 2008导入excel
    六十三、android pad
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6205559.html
Copyright © 2011-2022 走看看