【问题标题】:calling Qprocess with arguments containing spaces - Windows使用包含空格的参数调用 Qpr​​ocess - Windows
【发布时间】:2015-08-27 14:45:04
【问题描述】:

我正在尝试使用qprocess 调用可执行文件并传递一些可能(并且很可能会)包含空格(不是全部)的参数。 可执行文件是与Py2exe 打包的python 脚本。 python 脚本使用 optparse 解析参数。

如果我在cmd.exe 中调用py2exe.exe,调用是这样的:

pythonExecutable.exe -aarg_a -barg_b -c"path with spaces" -darg_d

这样的调用会成功。

我想通过使用QprocessQt 应用程序来执行此操作,但我找不到方法来执行此操作,因为Qprocess 会删除所有引号(""),从而在出现空格的地方留下参数被破坏.

我似乎遗漏了一些东西,有人可以帮忙解决这个问题吗?

【问题讨论】:

标签: windows qt qprocess


【解决方案1】:

如果你以更正确的方式使用 QProcess,那将不是什么大问题

QString program = "pythonExecutable.exe";
QStringList arguments;
arguments <<"-aarg_a"<< "-barg_b"<< "-c\"path with spaces\""<< "-darg_d";

QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);

通常当你有带空格的参数并且不需要“符号”时

您只需在 QStringList 中传递参数

QString program = "pythonExecutable.exe";
QStringList arguments;
arguments <<"a"<< "path with spaces";

QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);

此程序是 Qt 文档Here 中列出的示例程序的修改版本

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-08
    • 2013-03-30
    • 2015-11-25
    • 1970-01-01
    • 2018-05-30
    • 1970-01-01
    • 2011-08-26
    • 2018-05-22
    相关资源
    最近更新 更多