我有一個python代碼,我正在調用shell命令。在那裏我做了shell命令代碼的部分是:/bin/sh:line 62:to:command not found
try:
def parse(text_list):
text = '\n'.join(text_list)
cwd = os.getcwd()
os.chdir("/var/www/html/alenza/hdfs/user/alenza/sree_account/sree_project/src/core/data_analysis/syntaxnet/models/syntaxnet")
synnet_output = subprocess.check_output(["echo '%s' | syntaxnet/demo.sh 2>/dev/null"%text], shell = True)
os.chdir(cwd)
return synnet_output
except Exception as e:
sys.stdout.write(str(e))
現在,當我運行了一些樣品輸入(我做cat /home/sree/example.json | python parse.py
),它工作正常本地文件的代碼,我得到所需的輸出。但我想在我的HDFS(相同cat
命令,但輸入文件路徑是從HDFS),其中包含完全相同的類型JSON條目的運行與輸入的代碼,它失敗,出現錯誤:
/bin/sh: line 62: to: command not found
list index out of range
我讀過堆棧溢出的類似問題,解決方案是爲被調用的shell腳本包含一個Shebang行。我在demo.sh
腳本中有shebang行#!/usr/bin/bash
。
另外,which bash
給出/usr/bin/bash
。
有人請詳細說明。
看起來像你的問題不包括你真正需要幫助的代碼。看看你是否可以削減到[mcve]。 – tripleee