I want to obtain the (zsh) shell prompt in a python script. Simply usingimport osprompt = os.environ['PS1']seems not to be the right way, because PS1 is usually not forwarded to subprocesses. In the same manner env | grep PS in a shell fails.So I concluded that I should probably start an interactive shell as subprocess and querry its prompt. From a shell I can just dozsh -c -i 'echo $PS1'(must be single quotes, double quotes fail)I tried to do the same from python(2.7) with subprocess like this:print subprocess.check_output(['-i','-c',r'echo $PS1'],executable=/bin/zsh)This fails withsubprocess.CalledProcessError: Command '['-i', '-c', 'echo $PS1']' returned non-zero exit status 127I think this is not because of the $PS1 but due to the way how i provide the echo-part as argument, because also echoing bare strings in this way fails.Trying back and forth various combinations I ended up withprompt =  subprocess.check_output(zsh -c -i 'echo $PS1',shell=True,executable=/bin/zsh)which seems to do the job but seems wrong to me as this is starting a shell and in that shell calling yet another shell with -c -i 'echo $PS1'.What's the correct way of obtaining the shell prompt.
obtain shell prompt in python
shell;zsh;python
print subprocess.check_output(['zsh','-i','-c','echo $PS1'])When running zsh from another shell, the quotes around echo $PS1 are necessary so that the whole string is passed as the single argument after -c.  They had to be single quotes because in double-quotes, the first shell would have expanded $PS1.In Python, the whole command is a single string, so it is quoted like any other string.  Adding a second set is like typing 'echo $PS1' (with the quotes) into zsh - the shell looks for, and fails to find, an executable named 'echo $PS1'.