0

I have a snippet of code which works:

p = subprocess.Popen('psftp servername'.split(),stdin=subprocess.PIPE, tdout=subprocess.PIPE, shell=True)   
p.stdin.write('lcd P:\\ORACLE_UNIX\\Development\n')    
p.stdin.write('get //opt//jboss//current//server//default//conf//DMS.properties\n')    
p.stdin.write('bye\n')    
p.stdout.close()    
p.stdin.close()

But when I have a variable set (as I will refer to the server in other parts):

devserv='servername'  
p = subprocess.Popen('psftp' +devserv.split(),stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
p.stdin.write('lcd P:\\ORACLE_UNIX\\Development\n')    
p.stdin.write('get //opt//jboss//current//server//default//conf//DMS.properties\n')    
p.stdin.write('bye\n')    
p.stdout.close()    
p.stdin.close()

...I always get TypeError: cannot concatenate 'str' and 'list' objects. Why?

2 Answers 2

1

I think you need to replace

'psftp' +devserv.split()

with

('psftp' +devserv).split()

You need to build the string first and then call split on the completed string.

Sign up to request clarification or add additional context in comments.

Comments

1

devserver.split() returns a list, which is why you're seeing that error - you're trying to concatenate a string with a list.

You could try this instead:

p = subprocess.Popen(['psftp', devserver], stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)

.split() is no longer needed since you already have the cmd and args as seperate strings.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.