0

I am trying to pass a string literal to a Popen command, but it is isn't working:

subprocess.Popen(['/usr/bin/festival', '-b', '(SayText "%s")']) % text

The idea is that I want to pass text into the Popen command, which calls the program festival, which will read the input text.

Is it possible to pass a string literal inside a popen command? My guess is that this isn't working because the Popen commands are in a list.

2 Answers 2

1

You are correct, format the list element, and not the result of Popen or the argument list:

festivalCmd = '(SayText "%s")' % text.replace('"', '')
subprocess.Popen(['/usr/bin/festival', '-b', festivalCmd])

The call to replace ensures that you're correctly handing inputs like foo"bar without failing.

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

1 Comment

this doesn't seem to work for me, for a list.. but to use a much simpler example. gist.github.com/gartha1/29ac8d4431f0bb019ef017e467d01e67 now look at the output from wmic or task manager, re the command line gist.github.com/gartha1/eae1a16d55950fc5312ed01a461191bf c:\windows\system32\calc.exe "--profile-directory=\"Profile 3\"" Or if I try to use the example you do.. gist.github.com/gartha1/9d70278a278a8840cf14908ef5600572 it still doesn' tpass literal quotes correctly.
0

Your syntax is wrong. I don't know much about festival speech synth system but if you wrote it like this, that would be work:

subprocess.Popen(['/usr/bin/festival', '-b', '(SayText "%s")' % text]) 

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.