看板 Python 關於我們 聯絡資訊
※ 引述《IMPOSSIBLEr (不口人)》之銘言: : 小弟最近工作上需要寫一個簡單的script來控制公司內部的server : 因為控制server的script是用python : 而我的環境是linux,所以我在python外面包了shell, : 也就是用shell去呼叫python來控制server : 但是我的shell script和python script都需要用到一些 : 環境參數像是hostname之類的東西。 : 有什麼辦法是最簡單的,我只要另外提供一個.properties檔 : 然後給兩種語言都可以吃呢? : 謝謝 參考 repo (from Android) 的作法 #!/bin/sh ## Python & shell共用,參數可以放這裡 ## repo default configuration REPO_URL='http://android.git.kernel.org/tools/repo.git' REPO_REV='stable' magic='--calling-python-from-/bin/sh--' # 對 shell 來說是 exec (執行完離開) # 對 python 來說是字串 + comment """ """ #xxx """exec" python -E "$0" "$@" """#$magic" # 以下是純 python 程式 if __name__ == '__main__': import sys if sys.argv[-1] == '#%s' % magic: del sys.argv[-1] del magic -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.222.246