- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 Ubuntu 12.4,并且安装了 matlab。通常,为了从终端调用 matlab,我必须输入“~/MATLAB/bin/matlab”。显然这有点烦人,所以我通过添加
为这个命令起别名alias matlab='sh ~/MATLAB/bin/matlab'
到.bashrc。现在一切都很顺利,在终端 (bash) 中输入“matlab”可以在任何目录下工作。
当我尝试从 python 脚本调用 Matlab 时出现问题。有这样的声明:
>>> commands.getoutput('matlab')
'sh: 1: matlab: not found'
好像别名没有被识别。只是为了确保:
>>> commands.getoutput('~/MATLAB/bin/matlab')
像魅力一样工作,并且
>>> commands.getoutput('echo $SHELL')
'/bin/bash'
确实验证了 python 正在尝试在 bash 中执行 cmd...
知道这里发生了什么吗?为什么不识别别名?如何/可以修复它?
谢谢!
最佳答案
将 matlab
二进制路径添加到您的 PATH
环境变量。
PATH=~/MATLAB/bin/:$PATH
export PATH
然后python
会找到matlab
:
>>> commands.getoutput('matlab')
我 认为 commands
不知道您的 shell 当前的别名。但是 PATH
等环境变量仍然存在。
关于python - python (commands.getoutput) 无法识别带别名的 Linux 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11761300/
这个问题在这里已经有了答案: Store output of subprocess.Popen call in a string [duplicate] (15 个回答) 关闭4年前。 我想从 pyt
我正在努力用子进程替换 commands.getoutput。请看下面的代码: import subprocess import commands dir = subprocess.check_out
我有一个 java 程序,我必须从 python 运行,获取输出并将结果存储在 3 个变量中(如果它按预期工作,应该打印 3 个值,每个值在不同的行上)。 这是我正在使用的代码: stdout1 =
我在 Windows 中使用 python 3.6,我的目标是运行 cmd 命令并将输出作为字符串保存在变量中。我正在使用子进程及其对象,例如 check_output、Popen and Commu
问题看起来很简单,但是经过一天的谷歌搜索和查看 stackoverflow 后我找不到任何解决方案。最初我正在开发一个简单的等 ionic 体,它将每 30 分钟向本地网络服务器发送一个特定请求,解析
python : print("Active Device:"+subprocess.getoutput("ip link|grep \"state UP\"|cut -d : -f 2|cut -d
我正在使用 Ubuntu 12.4,并且安装了 matlab。通常,为了从终端调用 matlab,我必须输入“~/MATLAB/bin/matlab”。显然这有点烦人,所以我通过添加 为这个命令起别名
commands.getoutput() 在当前的 Python 2.x 中被弃用,并在 Py3k 中被移除。 如何在干净的 Python 3 中获取类似信息? 最佳答案 逐字等效为 subproce
本文整理了Java中org.gradle.api.tasks.bundling.Zip.getOutputs()方法的一些代码示例,展示了Zip.getOutputs()的具体用法。这些代码示例主要来
有没有办法让 subprocess.getoutput 处理不是有效 UTF-8 的输出?如果命令的输出返回非 UTF-8 字符,则会引发异常。但是,该函数似乎没有编码参数。 File "foo.py
自从在 Android Gradle 插件 0.13.0 中升级到 gradle 2.1 后,这个问题就出现了,但我一直无法理解为什么有时会记录此警告。 考虑此 block 以根据变体类型重命名 AP
本文整理了Java中org.embl.ebi.escience.scufl.enactor.WorkflowInstance.getOutput()方法的一些代码示例,展示了WorkflowInsta
本文整理了Java中com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType.getOutput()方法的一些代码示例,展示了
无法找到方法'com.android.build.gradle.internal.variant.BaseVariantData.getOutputs()Ljava/util/List 无法找到方法'
错误:无法找到方法“com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;”。此意外错误的可能原因包括: Gradl
构建.gradle buildscript { ext.kotlin_version = '1.1.51' repositories { jcenter()
这是我和 friend 在使用Android Studio 2.3.1时开发的一个项目。升级到 Android Studio 3.0 后。发生此错误: Error:Unable to find met
Error:Unable to find method 'com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;'.
尝试使用 Android Studio 3.0 Canary 1 启动新的 Kotlin 项目会显示此错误。完整跟踪: Error:Unable to find method 'com.android
我是一名优秀的程序员,十分优秀!