Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 具有多个参数的QProcess启动进程(blender.exe)_C++_Windows_Qt_Qprocess - Fatal编程技术网

C++ 具有多个参数的QProcess启动进程(blender.exe)

C++ 具有多个参数的QProcess启动进程(blender.exe),c++,windows,qt,qprocess,C++,Windows,Qt,Qprocess,我尝试使用QProcess(在Windows上)从程序(FaceModifier.exe)内部启动blender.exe。该命令遵循以下结构: '混合器路径'--background'混合文件路径'--python'python脚本路径'--'python脚本的附加参数' 一个完整的例子(如果我把它输入cmd.exe,它就可以工作)是 “C:\Program Files\Blender Foundation\Blender\Blender.exe”--背景“C:\Program Files(x8

我尝试使用
QProcess
(在Windows上)从程序(FaceModifier.exe)内部启动blender.exe。该命令遵循以下结构:

'混合器路径'--background'混合文件路径'--python'python脚本路径'--'python脚本的附加参数'

一个完整的例子(如果我把它输入cmd.exe,它就可以工作)是

“C:\Program Files\Blender Foundation\Blender\Blender.exe”--背景“C:\Program Files(x86)\FaceModifier\Resources\GenericHeadMesh.blend”--python“C:\Program Files(x86)\FaceModifier\python\local.py”--“C:\Users\Gunnar\Documents\FaceModifier\Output\”

现在,在我的程序中,我对路径进行了转义,并用引号将它们括起来,这样我就有了类似的东西

std::string blenderPath := "\"C:\\Program Files\\Blender Foundation\\Blender\\blender.exe\""
对于QProcess,我将所有参数输入到带有前导
/c
的QStringList中,因此它被视为单个命令,并将其传递给
cmd.exe

我的问题是我不能执行这个。如果我手动将命令(传递给QProcess,而不是上面的命令)键入cmd,也不会

启动流程的函数如下所示:

void PythonConnector::createSubprocess(const QStringList &args)
{
    QProcess *process = new Process();
    process->start("cmd.exe", args);
    process->waitForFinished(-1);

    QString result(process->readAll());
    qDebug() << "result: " << result;    // this gives just an empty string

    process->close();
}
// for the documents path
CoInitialize(NULL);
TCHAR *myDocuments = 0;
SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &myDocuments);
CString temp(myDocuments);
CT2CA tempConv(temp);
std::string outputFolderPath(tempConv);
outputFolderPath += "\\FaceModifier\\Output\\";
outputFolderPath = pH.ExcapeString(outputFolderPath);
CoTaskMemFree(myDocuments);

blenderPath = pH.EscapeString(blenderPath);

std::string meshGlobalPath = "\"" + pH.GetResourcesPath() + "GenericHeadMesh.blend" + "\"";
std::string pythonGlobalPath = "\"" + pH.GetPythonPath() + "global.py" + "\"";

QStringList args;
args << "/c" << QString::fromStdString(blenderPath) << "--background" << QString::fromStdString(meshGlobalPath) << "--python" << QString::fromStdString(pythonGlobalPath) << "--" << QString::fromStdString("\"" + outputFolderPath "\"");
pC.createSubprocess(args);
使用qDebug调试args列表会产生以下输出(这些输出实际上来自Visual Studio 2013中的调试,因此路径不同):

而来自
createSubprocess
结果
调试只会给出

如果我手动将此命令键入cmd,如下所示:

void PythonConnector::createSubprocess(const QStringList &args)
{
    QProcess *process = new Process();
    process->start("cmd.exe", args);
    process->waitForFinished(-1);

    QString result(process->readAll());
    qDebug() << "result: " << result;    // this gives just an empty string

    process->close();
}
// for the documents path
CoInitialize(NULL);
TCHAR *myDocuments = 0;
SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &myDocuments);
CString temp(myDocuments);
CT2CA tempConv(temp);
std::string outputFolderPath(tempConv);
outputFolderPath += "\\FaceModifier\\Output\\";
outputFolderPath = pH.ExcapeString(outputFolderPath);
CoTaskMemFree(myDocuments);

blenderPath = pH.EscapeString(blenderPath);

std::string meshGlobalPath = "\"" + pH.GetResourcesPath() + "GenericHeadMesh.blend" + "\"";
std::string pythonGlobalPath = "\"" + pH.GetPythonPath() + "global.py" + "\"";

QStringList args;
args << "/c" << QString::fromStdString(blenderPath) << "--background" << QString::fromStdString(meshGlobalPath) << "--python" << QString::fromStdString(pythonGlobalPath) << "--" << QString::fromStdString("\"" + outputFolderPath "\"");
pC.createSubprocess(args);
cmd/c“c:\Program Files\Blender Foundation\Blender\Blender.exe”--背景“c:\Users\Gunnar\documents\visual studio 2013\Projects\FaceModifier\x64\Release\Resources\GenericHeadMesh.blend”--python“c:\Users\Gunnar\documents\visual studio 2013\Projects\FaceModifier\x64\Release\python\global.py”--“C:\Users\Gunnar\Documents\FaceModifier\Output\”

我发现
命令“C:\\Program”拼写错误或找不到。
对于不同的引用也一样,有和没有这样的转义

std::string blenderPath := "\"C:\\Program Files\\Blender Foundation\\Blender\\blender.exe\""
cmd“/c \”c:\Program Files\Blender Foundation\Blender\Blender.exe \”-后台\“c:\Users\Gunnar\documents\visual studio 2013\Projects\FaceModifier\x64\Release\Resources\GenericHeadMesh.blend \”-python \”c:\Users\Gunnar\documents\visual studio 2013\Projects\FaceModifier\x64\Release\python\global.py \--\“C:\Users\Gunnar\Documents\FaceModifier\Output\\”

只是打字

cmd/c“c:\Program Files\Blender Foundation\Blender\Blender.exe”

很好,但这显然不是我需要的

我不知道该怎么做才能让它工作。有人能告诉我我的错误是什么吗

更新:

好的,理论上它现在起作用了(多亏了艾哈迈德),但它确实在路径上有所进展。如果我在
..\Documents\FaceModifier
中有.blend和.py,那么它可以工作,如果它们在
C:\Program Files(x86)\FaceModifier\
中(我的程序安装的地方),那么它就不能工作。我怎样才能做到这一点?我更愿意这样做,这样我就不必复制那边的文件。

您不需要引用或双引用文件路径,QProccess已经可以处理了, 将这部分代码更改为:

std::string meshGlobalPath = pH.GetResourcesPath() + "GenericHeadMesh.blend" ;
std::string pythonGlobalPath = pH.GetPythonPath() + "global.py" ;

QStringList args;
args << "/c" << QString::fromStdString(blenderPath) << "--background" 
     << QString::fromStdString(meshGlobalPath) << "--python" 
     << QString::fromStdString(pythonGlobalPath) << "--"
     << QString::fromStdString(outputFolderPath);
std::string meshGlobalPath=pH.GetResourcesPath()+“GenericHeadMesh.blend”;
std::string pythonGlobalPath=pH.GetPythonPath()+“global.py”;
QStringList-args;

args您不需要引用或双引号文件路径,QProccess已经处理了, 将这部分代码更改为:

std::string meshGlobalPath = pH.GetResourcesPath() + "GenericHeadMesh.blend" ;
std::string pythonGlobalPath = pH.GetPythonPath() + "global.py" ;

QStringList args;
args << "/c" << QString::fromStdString(blenderPath) << "--background" 
     << QString::fromStdString(meshGlobalPath) << "--python" 
     << QString::fromStdString(pythonGlobalPath) << "--"
     << QString::fromStdString(outputFolderPath);
std::string meshGlobalPath=pH.GetResourcesPath()+“GenericHeadMesh.blend”;
std::string pythonGlobalPath=pH.GetPythonPath()+“global.py”;
QStringList-args;

args好的,这有点有效。我了解这些文件(.blend和.py)的位置。如果它们位于
程序文件(x86)…
文档\visualstudio\…\x64\Release
中,则我无法工作。我猜这与权限有关,但它们只能通过此命令读取/执行,不能写入。有没有办法让它工作起来,这样我就不必把它们移到
输出
文件夹?你有没有试着直接运行
blender.exe
,而不运行
cmd.exe
?哦,是的!QProcess直接启动blender know,我删除了
/c
,所以剩下的都是从
--background
开始的,现在就可以工作了。非常感谢你!好吧,这有点用。我了解这些文件(.blend和.py)的位置。如果它们位于
程序文件(x86)…
文档\visualstudio\…\x64\Release
中,则我无法工作。我猜这与权限有关,但它们只能通过此命令读取/执行,不能写入。有没有办法让它工作起来,这样我就不必把它们移到
输出
文件夹?你有没有试着直接运行
blender.exe
,而不运行
cmd.exe
?哦,是的!QProcess直接启动blender know,我删除了
/c
,所以剩下的都是从
--background
开始的,现在就可以工作了。非常感谢你!