QProcess 不适用于 Windows 操作系统中的少数命令例如 npm 输出为例外无输出我已经安装了 npm操作系统:Windows

问题描述

我尝试使用 QProcess 来运行 npm 命令,但 QProcess 没有显示任何效果。我已经在我的系统上安装了 npm 并添加到系统环境(路径)中。但是其他命令如 python 可以工作。

输出为例外

from PyQt5.QtCore import QProcess

if __name__ == '__main__':
    q = QProcess()
    q.start('python --version')
    q.waitForReadyRead()
    print(q.readAllStandardOutput())
    print(q.readAllStandardError())

# OUTPUT
b'Python 3.6.0\r\n'
b''

输出

from PyQt5.QtCore import QProcess

if __name__ == '__main__':
    q = QProcess()
    q.start('npm --version')
    q.waitForReadyRead()
    print(q.readAllStandardOutput())
    print(q.readAllStandardError())

# OUTPUT
b''
b''

我已经安装了 npm

(venv) C:\Users\...\test-app>python --version
Python 3.6.0

(venv) C:\Users\...\test-app>npm --version
6.14.10

操作系统:Windows

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)