I am trying to access data from an object that has just unpickled and use that with
os.popen()
hitting error
Traceback (most recent call last):
File "tmpclient4.py", line 46, in <module>
stream = os.popen('%t.cmd', '%t.arg')
File "/usr/lib/python3.8/os.py", line 978, in popen
raise ValueError("invalid mode %r" % mode)
ValueError: invalid mode '%t.arg'
or error:
ValueError: invalid mode 'htop' #my object value
using
stream = os.popen('%t.cmd', '%t.arg')
or
stream = os.popen(t.cmd, t.arg)
code:
import socket
import pickle
import os
HEADERSIZE = 10
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.42.14', 666))
class Zeroquery:
# Initializer / Instance Attributes
def __init__(self, cmd, arg):
self.cmd = cmd
self.arg = arg
while True:
full_msg = b''
new_msg = True
while True:
msg = s.recv(16)
if new_msg:
print("new msg len:",msg[:HEADERSIZE])
msglen = int(msg[:HEADERSIZE])
new_msg = False
print(f"full message length: {msglen}")
full_msg += msg
print(len(full_msg))
if len(full_msg)-HEADERSIZE == msglen:
print("full msg recvd")
t = pickle.loads(full_msg[HEADERSIZE:])
print(t.cmd, t.arg)
if t.cmd:
stream = os.popen(t.cmd, t.arg)
output = stream.read()
print(output)
new_msg = True
full_msg = b""
My question is how do I use os.popen using my object data?