0

I have a small python snippet that calls a larger program (I did not write the larger one).

call(['function1', file1, file2, 'data.labels=abc, xyz'])

The above works.

input ='abc, xyz'

Now I want to input "abc, xyz" as a variable holding this value

call(['function1', file1, file2, 'data.labels=input'])

but it does not work.

How can I pass a variable value into variable data.labels within call subprocess.

asked Sep 9, 2014 at 20:11
2
  • A more specific question might be, "how do I take the string 'abc, xyz' and somehow get the string 'data.labels=abc, xyz'"? The answer isn't really specific to call at all, just ordinary string manipulation. Commented Sep 9, 2014 at 20:16
  • @Kevin: It is specific to subprocess.call() on Windows where CreateProcess() is used to start the child process that accepts a single string as a command, see subprocess.list2cmdline(). In other words, you can't pass arbitrary unescaped values on Windows because list2cmdline() doesn't cover all possible cases. Commented Sep 9, 2014 at 22:29

3 Answers 3

2
call(['function1', file1, file2, 'data.labels=%s' % input])
chepner
539k77 gold badges596 silver badges748 bronze badges
answered Sep 9, 2014 at 20:15
Sign up to request clarification or add additional context in comments.

1 Comment

'data.labels=' + input seems like a more natural code.
1

Or

call(['function1', file1, file2, 'data.labels=' + input)

If for some reason, input is not a string.

call(['function1', file1, file2, 'data.labels=' + str(input) )
answered Sep 9, 2014 at 20:37

Comments

0

Another way to do the same:

call(['function1', file1, file2, 'data.labels={0}'.format(input)])
answered Sep 9, 2014 at 20:18

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.