0

Here's a copy of my python terminal:

>> import subprocess
>> import shlex
>> host = 'myhost'
>> subprocess.Popen(shlex.split('ssh -o LogLevel=error -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes %s "hostname --short"' % (host))).communicate()
myhost
(None, None)

I would expect the output to be ('myhost', None). Why isn't the output being stored in the return tuple for communicate()?

user2824889
  • 1,085
  • 5
  • 16
  • 28

1 Answers1

2

You need to give the subprocess.Popen call a stdout argument. For example:

>>> subprocess.Popen("ls", stdout=subprocess.PIPE).communicate()
(b'Vagrantfile\n', None)
>>>

The output of the command then appears where you expect it.

holdenweb
  • 33,305
  • 7
  • 57
  • 77