I have a shell and I use pwd to show in which directory I am. but when I'm in directory that it's a symlink it show the physical directory not the symlink
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]
If I have folder /home/foo/mime
that it's symlink to /usr/share/mime
when I call
execv('pwd', '/home/foo/mime')
I got /usr/share/mime
My code for shell look like this:
m = re.match(" *cd (.*)", form['command'])
if m:
path = m.group(1)
if path[0] != '/':
path = "%s/%s" % (form['path'], path)
if os.path.exists(path):
stdout.write(execv("pwd", path))
else:
stdout.write("false")
else:
try:
stdout.write(execv(form['command'], form['path']))
except OSError, e:
stdout.write(e.args[1])
And I have client in JavaScript
(probably returning result of the command and new path as JSON will be better).
Is there a way to make pwd
return path to the symlink instead of the physical directory.