쉘이 있고 pwd를 사용하여 어떤 디렉토리에 있는지 보여줍니다. 내가 디렉토리에있을 때 내가 폴더 /home/foo/mime
이있는 경우 그러나 그것은 심볼릭 링크가 있다는 그것이 내가 호출 할 때이 /usr/share/mime
에 심볼릭 링크 있다는 원래 디렉토리되지에게 심볼릭 링크파이썬에서 bash의 pwd가 심볼릭 링크를 확장합니다.
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]
을 보여
execv('pwd', '/home/foo/mime')
I 얻었다는/usr/쉘 주/MIME
내 코드는 다음과 같다 :
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])
그리고 JavaScript로 클라이언트를 가지고 있습니다.
(아마도 JSON이 더 좋으므로 명령 결과와 새 경로가 반환 될 것입니다).
pwd
원본 경로 대신 symlink에 경로를 반환하는 방법이 있습니까?
확실하지 않은 경우 : [os.getcwd()] (http://docs.python.org/library/os.html#os-file-dir) 현재 작업 디렉토리를 제공합니다. – bpgergo
또한 심볼릭 링크를 지원합니다 iirc – Jharwood