sh 1语法错误(尝试运行外部python脚本时发生意外

时间:2019-12-01 04:34:52

标签: python shell

因此,当尝试运行代码的程序尝试运行python脚本时,它将在shell中运行它。我确定它有一个Shebang,所以它运行了正确的解释器,但它不断提出

sh: 1: Syntax error: "(" unexpected

尽管明确将其设置为

#!/usr/bin/env python3

这是有问题的代码

#!/usr/bin/env python3
# Four arguments, password host channel and message.
# EG: "ircbot_message.py hunter2 example.com #adminchannel ADMINHELP"
import sys
import socket

def pack():

    try:
        data = sys.argv[4:]
        print(data)
    except:
        data = "NO DATA SPECIFIED"
    data = str(data)
    data = bytes(data, "ascii")
    nudge(data)

def nudge(data):
    HOST = sys.argv[2]
    PORT = 45678
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))
    s.send(data)
    s.close()

if __name__ == "__main__" and len(sys.argv) > 1:  # If not imported and more than one argument
    pack()

我正在加拿大专用盒子上的云服务器上运行ubuntu 18.04服务器版本。 哦,是python 3.6.8。

添加更多信息。将命令发送到py脚本的代码段

/proc/ext_python(var/script, var/args, var/scriptsprefix = 1)
    if(scriptsprefix) script = "scripts/" + script

    if(world.system_type == MS_WINDOWS)
        script = replacetext(script, "/", "\\")

    var/command = config.python_path + " " + script + " " + args
    shell("[command]")
    return

并命名为

usr/bin/python3 ircbot_message.py commskey "iphere" null "ADMIN - HELP ME IM DYING INSIDE"

和DM

/proc/send2irc(var/msg, var/admin = 0)
    if(config.use_irc_bot)
        paranoid_sanitize(msg)
        if(admin)
            msg = "ADMIN - [msg]"
        // 3rd param is unused in the bot, would spend time to fix this but I'm lazy. - Jon
        ext_python("ircbot_message.py", "[config.comms_password] [config.irc_bot_host] null [msg]")
    return

0 个答案:

没有答案