我正在尝试调试一个突然停止工作的Sublime插件.我在插件中有以下代码.proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=info, cwd=home)data...

我正在尝试调试一个突然停止工作的Sublime插件.
我在插件中有以下代码.
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=info, cwd=home)
data = proc.communicate()[0]
基本上,它正在执行一个文件,文件的顶部是#!/usr/bin/env php.当我运行命令时,我得到env:php:没有这样的文件或目录错误消息.
我通过使用绝对路径修复了它.
解决方案1:#!/usr/bin/env /Applications/MAMP/bin/php/php5.5.18/bin/php
虽然这有效,但我真的想知道为什么在我在终端中执行php并且在$PATH变量中定义了该命令的路径时,为什么php不可用.
我怎样才能解决这个问题?
解决方法:
与在docs中一样,您需要传递shell = True作为subprocess.Popen的参数:
If shell is True, the specified command will be executed through the shell. This can be useful if you are using Python primarily for the enhanced control flow it offers over most system shells and still want convenient access to other shell features such as shell pipes, filename wildcards, environment variable expansion, and expansion of ~ to a user’s home directory.
尽管不鼓励使用shell = True due to security considerations.
本文标题为:php-Python子进程无法识别$PATH中的命令


基础教程推荐
- Python中re模块:匹配开头/结尾(^/$) 2022-09-02
- centos升级python2.7到3.6之后造成yum命令报错 2023-09-03
- python读取Windows注册表的示例代码 2022-09-03
- python机器学习Github已达8.9Kstars模型解释器LIME 2023-08-09
- Python sklearn库三种常用编码格式实例 2022-10-20
- python的内存管理 2023-09-03
- 在Centos7 部署Python3 + Django + Nginx + Uwsgi 2023-09-04
- Python实现人机中国象棋游戏 2023-08-11
- windows和linux下 Python2,Python3 的环境及安装 2023-09-04
- python之Linux基础(三) 2023-09-04