下面是我試圖使用python如何從蟒蛇,如果其他UNIX命令執行,並得到RET值
from subprocess import Popen, PIPE
cmd = 'if (-e "../a.txt") then \n ln -s ../a.txt . \n else \n echo "file is not present " \n endif'
ret_val = subprocess.call(cmd,shell="True")
在執行時,執行代碼提供以下錯誤消息
/bin/sh: -c: line 5: syntax error: unexpected end of file
確實在你的shell命令工作? – user2393256
您應該將'True'傳遞給'shell',而不是字符串'「True」'。 – DeepSpace
這是醜陋的......強烈建議將邏輯放入python代碼中。 – wim