方法一:把cygwin的bin配置到环境变量里,这样做了以后在cmd.exe里也可以使用linux的命令
def exe_command(command): p = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell='Linux'.__eq__(platform.system())
) return p.communicate()
方法二:在运行的时候指定sh.exe位置
print subprocess.Popen(
args=["D:/Git/bin/sh.exe", "-c", "grep 'xiaol' E:/test/name.txt"],
shell=True,
stdout=subprocess.PIPE
).stdout.read()