Message from Python discussions

November 2018

— Not a commands script with os. System

— 

Maybe subprocess.Popen("cmd", shell = True, stdin/stdout = PIPE) and .communicate function could work well

— Tried it
though: .communicate function returning an error:

    self.stdin.write(input)
TypeError: a bytes-like object is required, not 'str'

Message permanent page

— My code:

 prog = subprocess.Popen(cmd, stdin = subprocess.PIPE, stdout = subprocess.PIPE,stderr = subprocess.PIPE,shell=True)
prog.communicate(input='ping 8.8.8.8')

Message permanent page

— Seems like a string must be encoded

— Tried it as well but my app got stuck 😐

— Are you reading output of this command?

— I followed this:
https://stackoverflow.com/questions/44989808/subprocess-typeerror-a-bytes-like-object-is-required-not-str-python-2
but nothing

Message permanent page

— No

— But it opens cmd..

— 

   cmd = 'start COLOR 1f ' + '^&' + 'mode con: cols=200 lines=50 ' + '^&' + 'ssh ' + username.get() + '' + ip_num.get()
prog = subprocess.Popen(cmd, stdin = subprocess.PIPE, stdout = subprocess.PIPE,stderr = subprocess.PIPE,shell=True)
prog.stdin.flush()
prog.stdout.flush()

prog.communicate(input='ping 8.8.8.8')

Message permanent page

— Need help