#!/usr/bin/python import os import sys from subprocess import check_output samba_root = os.environ['SAMBA_ROOT'] win_drive = 'Z' def win2nix(s): global win_drive if len(s) > 3 and s[1] == ':' and s[2] == '\\': win_drive = s[0] return "%s/%s" % (samba_root, s[3:].replace('\\', '/')) return s def nix2win(s): for line in s.splitlines(): if line.startswith(samba_root): print "%s:%s" % (win_drive, line.replace('/', '\\')) else: print line if __name__ == '__main__': params = [win2nix(i) for i in sys.argv[1:]] # Note: commands like "cd" would require "shell=true" r = check_output(params) nix2win(r)