Python code to scp a file fails with name resolution issue
<p>I am trying to scp a file from my local linux machine to a remote linux machine.
Here is the code that i am trying</p>

<pre><code>filename = '/tmp/myfile'
remotepath = '/tmp'
command = 'nodeattr'
sproc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
server = sproc.communicate()

print "connecting to",server[0]

p = subprocess.Popen(["scp", filename, "root@"+server[0]+":"+remotepath])
sts = p.wait()
</code></pre>

<p>When I run the above, I get an error as below</p>

<blockquote>
  <p>connecting to abc.local</p>
  
  <p>ssh: Could not resolve hostname abc.local : Name or service not known<br>
  lost connection</p>
</blockquote>

<p>However, when I do a ssh on command line, it allows me to connect to the remote host <code>abc.local</code> and I don't have an issue. But when I am using <code>subprocess</code>, I am getting this error.</p>

<p>Any idea if I am using the subprocess in a wrong way?</p>