在QT中获取Python脚本的输出
Get output from Python script in QT
我想运行用Python编写的脚本并从中获得所有输出。这是我的cpp代码
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
QString exe = "python script.py";
process.start(exe);
process.waitForFinished(-1);
QString output(process.readAllStandardOutput());
qDebug() << output << endl;
和my script.py
import sys
print("Hello world!")
奇怪的是,当我把"python script.py"改为"ping google.com"时,它就像一个魅力一样工作。我也检查了我的cmd,但似乎我的Python安装也很好。我哪里做错了?
[编辑1]回声%路径%
C:ProgramDataOracleJavajavapath;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Windowssystem32configsystemprofile.dnxbin;C:Program FilesMicrosoft DNXDnvm;C:Program FilesMicrosoft SQL Server120ToolsBinn;C:Program FilesMicrosoft SQL Server130ToolsBinn;C:Program Files (x86)SkypePhone;C:Program FilesMicrosoftWeb Platform Installer;C:Program Files (x86)Microsoft ASP.NETASP.NET Web Pagesv1.0;C:Program Files (x86)Windows Kits8.0Windows Performance Toolkit;C:Program FilesMicrosoft SQL Server110ToolsBinn;C:Program Files (x86)GtkSharp2.12bin;C:Program Filesnodejs;C:Program FilesGitcmd;C:Program Files (x86)Microsoft SDKsTypeScript1.0;C:UsersMichaAppDataLocalProgramsPythonPython35-32Scripts;C:UsersMichaAppDataLocalProgramsPythonPython35-32;C:NVPACKgradle-2.9bin;C:NVPACKapache-ant-1.8.2bin;C:NVPACKjdk1.8.0_77bin;C:NVPACKandroid-ndk-r12b;C:NVPACKandroid-sdk-windowsextrasandroidsupport;C:NVPACKandroid-sdk-windowsbuild-tools;C:NVPACKandroid-sdk-windowsplatform-tools;C:NVPACKandroid-sdk-windowstools;C:UsersMicha?AppDataLocalatombin;C:UsersMichaAppDataRoamingnpm;C:Program Files (x86)Microsoft VS Codebin
您需要修改您的PATH
环境变量。
如果您使用官方安装程序并接受默认安装位置,python可能会在例如C:/Python27
, C:/Python35
等位置。所以你需要添加这些路径,也可能是C:/Python27/Scripts
。
参见:什么是PATH和其他环境变量,以及如何设置或使用它们
相关文章:
- 从C++应用获取PowerShell脚本输出
- 将.init_array部分包含在链接器脚本中会产生不可用的输出
- 如何从 bash 脚本捕获终端输出并将其显示在我的 Qt UI 中?
- 将Python脚本的输出链接到C 程序的输入
- 从c++程序运行shell脚本会自动将shell脚本的输出显示到控制台吗
- 在Qt应用程序中读取python脚本C++输出
- Shell脚本终止程序,但导致无法写入输出文件
- 如何将C++程序的输出用作 Bash 脚本中的变量
- 将C++程序输出与 Python 脚本链接
- CGI 渲染到屏幕外壳脚本输出
- 从C++执行 bash 脚本并读取其输出 ubuntu sdk
- 关闭标准输出和脚本
- 如何通过脚本将输出写入C++中的文本文件
- 将外部进程的输出管道传输到正在运行的脚本C++
- 使用C++或Bash/Shell脚本评估后台linux命令的输出
- 解释R脚本的valgrind输出
- 在QT中获取Python脚本的输出
- 从c++调用Python脚本并使用其输出
- 如何在c++中重定向读取bash脚本的输出
- 将python脚本输出重定向到grep