How to execute shell command get the output and pwd after the command in Python
Question: How can I execute a shell command, can be complicated like normal command in
bash command line, get the output of that command and pwd after execution?

I used function like this:

    
    
    import subprocess as sub
    
    def execv(command, path):
        p = sub.Popen(['/bin/bash', '-c', command],
                        stdout=sub.PIPE, stderr=sub.STDOUT, cwd=path)
        return p.stdout.read()[:-1]
    

And I check if user use `cd` command but that will not work when user use
symlink to cd or other wierd way to change directory.

and I need a dictionary that hold `{'cwd': '<NEW PATH>', 'result': '<COMMAND
OUTPUT>'}`


Answer: If you use `subprocess.Popen`, you should get a pipe object that you can
`communicate()` for the command output and use `.pid()` to get the process id.
I'd be _really_ surprised if you can't find a method to get the current
working directory of a process by pid...

e.g.: <http://www.cyberciti.biz/tips/linux-report-current-working-directory-
of-process.html>

