python - 子进程调用在 python 中不起作用,但该命令在终端中起作用

标签 python subprocess fasttext

当我从终端运行 ./fasttext 时,它运行良好。但是当我使用 subprocess.check_output('./fasttext') 尝试它时,它给出的错误为。

错误

CalledProcessError                        
Traceback (most recent call last)
<ipython-input-11-a048dbef034f> in <module>()
      1 from subprocess import check_output
      2 from subprocess import call
----> 3 a1 = check_output('./fasttext')
      4 
      5 #a = check_output('./fasttext print-sentence-vectors ~/Vaiju/Project/all code and data/My Code/TrainedModels/wiki_unigrams.bin < 1fasttext.test.txt')

/home/vaijenath/anaconda2/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs)
    571         if cmd is None:
    572             cmd = popenargs[0]
--> 573         raise CalledProcessError(retcode, cmd, output=output)
    574     return output
    575 

CalledProcessError: Command './fasttext' returned non-zero exit status 1

我与笔记本中的 fasttext 位于同一目录中。

最佳答案

已解决。通过在调用中使用 shell=True 参数解决了该问题。

关于python - 子进程调用在 python 中不起作用,但该命令在终端中起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47572190/

相关文章:

python - 如何解析包含不确定数据模式的日志文件?

python - Popen 管道 2 cmd 挂起并且没有给出预期的结果

Python 子进程和 shell 输入重定向

python - 如何覆盖 sys.stdin 以复制输入流

python - 继续训练 FastText 模型

python-3.x - gensim 词嵌入(Word2Vec 和 FastText)模型中的 alpha 值?

python - 复制命令 fasttext 查询并保存 FastText 向量

python - 具有多个输入和多个输出列的 Pandas 应用、滚动、分组

python - HTC Vive 的 Maya 为 90 fps

python - pandas python 替换/删除 read_csv 中的连字符