Ich bin Anfänger in Python, ZMQ, Networking oder sogar Codierung im Allgemeinen, also bitte entschuldigen Sie meine Fehler.Senden Befehlszeilenargumente mit ZMQ und Python
Ich versuche, Anweisungen zu senden notepad.exe von meinem Desktop auf meinem Laptop so zu öffnen:
Hauptserver
import zmq
import subprocess
try:
raw_input
except NameError:
raw_input = input #for python 3
#This will handle all the sockets we will open on the mainServer
context = zmq.Context()
#Socket 1 - Using for instructions
instructions = context.socket(zmq.PUSH)
instructions.bind("tcp://*:5555")
#Socket 2 - Using for end of finished instructions
#doneWork = context.socket(zmq.PULL)
#instructions.bind("tcp://*:5556")
#Now we will press enter when the workers are ready
print("Press Enter when you want to send the instructions. Make sure test devices are ready")
_=raw_input()
print ("Sending tasks to test device. . .")
instruction_One= "subprocess.call(['C:\notepad.exe'])"
instructions.send_string('%s' %instruction_One)
und
CLIENT
import zmq
import sys
context = zmq.Context()
instructions = context.socket(zmq.PULL)
instructions.connect("tcp://192.168.0.12:5555")
while True:
instruction_One=instructions.recv()
string_of_instruction = instruction_One.decode("utf-8")
sys.std.out.write(string_of_instruction)
sys.std.out.flush()
Ich sende die Anweisungen in Form von Strings, die durch den Socket in Binärform codiert sind. Aber auf der Client-Seite (Laptop) kann alles, was ich hole, nicht über die Befehlszeile ausgeführt werden. Was ist der dumme Fehler, den ich mache?
eine schnelle Bearbeitung auf den Client-Code, sollte es C: \\ notepad.lnk Allerdings habe ich immer noch einen Fehler bei subprocess.call (string_of_instruction) erhalten – bananaCellPhone
'sys.std.out '->' sys.stdout' – falsetru
@falsetru oops danke! Obwohl das mir immer noch einen Fehler gab. Ich bin immer noch nicht sicher, wie man notepad.lnk nach dem Senden von Anweisungen über den Socket – bananaCellPhone