python-3.x - 找不到python子进程命令
问题描述
RHEL7 我注意到尝试运行“应该”在环境中的任何命令都会失败,但运行具有相对或绝对路径的命令会成功。
我想我可以手动将所有这些 cal 转换为 shell 函数,/bin/whatever
但如果有一种方法可以从 python 运行子进程而不必这样做,那就太好了。subprocess
我缺少一些设置参数吗?
这是一堆失败的案例:
me@server~ python3 --version
Python 3.6.6
me@server~ python3
Python 3.6.6 (default, Aug 27 2018, 10:45:14)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.run('ls')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/l/python3/lib/python3.6/subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "/l/python3/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/l/python3/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ls': 'ls'
>>> subprocess.run('ls', shell=True)
/bin/sh: ls: command not found
CompletedProcess(args='ls', returncode=127)
>>> subprocess.run(['ls'], shell=True)
/bin/sh: ls: command not found
CompletedProcess(args=['ls'], returncode=127)
>>> subprocess.run(['ls'], shell=True, executable='/bin/bash')
/bin/bash: ls: command not found
CompletedProcess(args=['ls'], returncode=127)
这是一个成功的:
>>> run('/bin/ls')
bin ld.script.arm-bbb ld.script.x86-galileo Makedefs make-errs platform-cmake uboot-tool xinu xinu.boot xinu.x86.boot
binaries ld.script.arm-qemu ld.script.x86-qemu Makedefs.EXAMPLE Makefile qex.exp version xinu.bin xinu.map
CompletedProcess(args='/bin/ls', returncode=0)
这是我 ssh 进入的系统:
me@server~ lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-ia32:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-ia32:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-ia32:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: RedHatEnterpriseServer
Description: Red Hat Enterprise Linux Server release 7.7 (Maipo)
Release: 7.7
Codename: Maipo
解决方案
推荐阅读
- java - Network 对象的 NetworkInfo.isConnected() 的替代方法(API 23 中已弃用)
- xml - POST_PRODUCT_DATA 调用中的 EUCompliance 数据不被接受
- python - 机器学习算法来查找相似或匹配的记录?
- php - 在函数中回显 get_post_meta()
- android - MediaStore contentResolver.insert() 在拍照时创建副本而不是替换现有文件(Android Q: 29)
- python - Python类型 - 如果它是None,有没有办法避免导入可选类型?
- ssl - 是否可以要求服务器*不*在其“服务器问候”中发送“证书请求”?
- assembly - 在 PIC 汇编中保留内存指令“Res”的使用
- machine-learning - 如何将 plot_importance 函数与 MultiOutputRegressor 一起使用?
- ios - Xcode 11,Vmware 中的错误当我在项目中添加 appicon 时,我收到此错误