2016-05-13 15 views
0

QProcess(Windowsの場合)を使用して、自分のプログラム(FaceModifier.exe)からblender.exeを起動しようとしています。コマンドは次の構造に従います。複数の引数を持つプロセスの開始プロセス(blender.exe)

'path-to-blender' - 背景 'path-to-blend-file' --python 'path-to-python-script' - 'additional-arg- \プログラムファイル\のBlender Foundationの\ブレンダー\ blender.exe:「

(私はcmd.exeのにそれを入力すると動作します)完全な例-pythonのスクリプトのために

」Cのようになり" - " C:¥Program Files(x86)¥FaceModifier¥Resources¥GenericHeadMesh.blend " - python" C:\ Program Files(x86)\ FaceModifier \ python \ local.py " - " C:\ Users \ Gunnar \ Documents \ FaceMo

今difier \出力\」ので、私は私がQStringListにすべての私の引数を養うQProcessするために、この

std::string blenderPath := "\"C:\\Program Files\\Blender Foundation\\Blender\\blender.exe\"" 

のようなものを持っている私のプログラム内で、私はパスを脱出し、重引用符でそれらを囲みます先頭に/cがあるので、1つのコマンドとして扱われ、cmd.exeに渡されます。

私の問題は、これが実行されることができないということです。私がコマンドを入力した場合(上記のものではなくQProcessに渡す)、cmdを手で入力しないでください。プロセスを開始

My機能は、次のようになります。

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); 

blenderPath

は、この関数に渡され、他の関数で、レジストリから読み込まれます。 (これらは、したがって、異なるパスのVisual Studio 2013でのデバッグから実際にある)これらの出力でqDebug結果と引数リストのデバッグ

std::string PathHandler::GetResourcesPath() 
{ 
    if(resourcesPath.empty()) 
     resourcesPath = GetFullPath("Resources\\"); 
    return resourcesPath; 
} 

std::string PathHandler::GetPythonPath() 
{ 
    if(pythonPath.empty()) 
     pythonPath = GetFullPath("python\\"); 
    return pythonPath; 
} 

std::string PathHandler::GetFullPath(const std::string &relPath) 
{ 
    char full[_MAX_PATH]; 
    _fullpath(full, relPath.c_str(), _MAX_PATH); 
    return EscapeString(std::string(full)); 
} 

std::string PathHandler::EscapeString(const std::string &input) 
{ 
    std::regex toReplace("\\\\"); 
    std::string output(input.begin(), input.end()); 
    output = std::regex_replace(output, toReplace, "\\\\"); 
    return output; 
} 


これらは私の他のヘルパー関数です

"/c" 
""C:\\Program Files\\Blender Foundation\\Blender\\blender.exe"" 
"--background" 
""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\\"" 

createSubprocessからのresultデバッグはちょうど""となります。

私はこのような手でcmdをに、このコマンドを入力した場合:

CMD/C "C:\プログラムファイル\のBlender Foundationの\ブレンダーの\ blender.exe" --background「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:\ユーザーはグンナー\ドキュメント\ \ FaceModifier \出力\/C"

私が持つとこの

CMDのようにエスケープすることなく、種々の異なるquotingsためThe command "C:\\Program" is either missspelled or couldn't be found. が同じ取得" C:\ Users \ Gunnar \ documents \ Visual Studio 2013 \ Projects \ FaceModifier \ x64 \ Release \ Resources \ GenericHeadMesh.blend \ Blender Foundation \ Blender \ C:\ Users \ Gunnar \ Documents \ FaceModifier \ Output \ Projects \ FaceModifier \ x64 \ Release \ python \ global.py \ " - \" C:\ Users \ Gunnar \ Documents \ \\ ""

だけ入力し

CMD/C "C:\プログラムファイル\のBlender Foundationの\ブレンダーの\ blender.exe"

が正常に動作しますが、それは私が必要なもの、明らかではありません。

私はこれを動作させるために、どうやってビルドしなければならないのか、私の頭を包み込むことはできません。誰かが私の間違いを教えてもらえますか?

UPDATE:
[OK]を、理論的にはそれが今(アーメドのおかげで)動作しますが、それは本当にかかわらず、パスにdepands。もし私が...\Documents\FaceModifierに.blendと.pyを持っていれば、C:\Program Files (x86)\FaceModifier\(私のプログラムがインストールされているところ)にあれば動作しません。それをどうすれば実現できますか?私はそこにそれらのファイルをコピーする必要はありませんので、私はそれを好むでしょう。

答えて

1

あなたはにあなたのコードのこの部分 変更、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); 
+0

やや動作する、[OK]をクリックします。私はこれらのファイル(.blendと.py)がどこにあるかを調べます。それらが 'Program Files(x86)...'または 'documents \ visual studio \ ... \ x64 \ Release'にある場合、私は動作しません。私はこれがパーミッションに関連していると思いますが、このコマンドでは書き込み/書き込みのみが行われます。これを動作させる方法はありますか? 'output'フォルダに移動する必要はありませんか? –

+0

'cmd.exe'なしで' blender.exe'を直接実行しようとしましたか? – ahmed

+1

ああ、はい! QProcessはブレンダーを直接開始し、 '/ c'を削除したので、残りの部分は' --background'から始まり、今すぐ動作します。どうもありがとうございました! –

関連する問題