繁体   English   中英

从 python,在 git-bash 中运行 python 脚本

[英]From python, run python script in git-bash

From python, I need to run a python file inside of git bash, while running in Windows.

也就是说,我有一个用 python 编写的配置脚本,它调用其他 python 脚本。 不幸的是,其中一些使用 Unix 命令,因此必须使用 ZAEA23489CE0AA9B6406EBB28 中的 git bash 运行它们

目前我正在使用这个:

cmd = f'{sys.executable} mydependency.py'
pipe = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
# waiting for pipe is handled later...

但是,这不起作用,给我一个cannot execute binary file的消息。 我怎样才能让它运行?

PS:对于更多的上下文, mydependency.py实际上是来自 simdjson ( https://github.com/simdjson/simdjson ) 项目的amalgamate.py脚本。

编辑:

我还尝试了以下方法:

  • 切换到运行或调用而不是 subprocess.Popen
  • 使用f'{git_bash_path} {sys.executable} mydependency.py'
  • 更改 shell 和 Popen,run 和 call 的可执行参数

我找到了一个解决方案:

cmd = git_bash_path # Found with glob.
pipe = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
pipe.communicate(input=f'{sys.executable} mydependency.py'.encode())

我不完全确定为什么会这样,如果有人有解释我会很高兴听到它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM