私はスレッディングやプロセスには新しく、他のフォーラムの投稿がたくさんあるにもかかわらず、実行可能ファイルを起動するためにCreateProcess()を取得できません。私の貧弱な理解から、私は正しいパラメータが設定されていると思うが、Create Process failed (267)
というエラーが出る。実行しようとしている実行ファイルは、xstというザイリンクススイートに属するコマンドラインツールです。私が望むのは、グローバル変数path
で定義されているディレクトリでxstを実行して、そこに格納されているいくつかのファイルで動作するようにすることです。 CreateProcess()のパラメータが間違っていますか?CreateProcess + Callコマンドラインツール
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <sddl.h>
#include <windows.h>
#include <AccCtrl.h>
#include <Aclapi.h>
std::string path = "C:\\FPGA\\BSP\\BSP\\Xilinx\\SingleItemTest\\";
void testXST(std::string filePath, std::string arguements) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
// Start the child process.
if (!CreateProcess(
LPTSTR(filePath.c_str()),
LPTSTR(arguements.c_str()),
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
LPTSTR(path.c_str()),
&si, // Pointer to STARTUPINFO structure
&pi) // Pointer to PROCESS_INFORMATION structure
)
{
printf("CreateProcess failed (%d).\n", GetLastError());
return;
}
// Wait until child process exits.
WaitForSingleObject(pi.hProcess, INFINITE);
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
int main()
{
std::string xstPath = "C:\\Xilinx\\14.7\\ISE_DS\\ISE\\bin\\nt\\xst.exe";
std::string args = " -h";
testXST(xstPath, args);
return 0;
}
私は、コマンドラインからどこでもそれを呼び出すことができますので、私は、正しい問題ではないはず、実行に直接パスを与えておりますので、XSTのために設定した環境変数がありますか?
'LPTSTR(filePath.c_str())、' - なぜ '(LPTSTR)'をキャストしていますか?これは、UNICODEアプリケーションを構築する場合は機能しません。キャストを削除し、コンパイルエラーがある場合は、適切な文字列タイプを使用してエラーを修正し、キャストによってエラーを隠蔽しないでください。 – PaulMcKenzie
'std :: wstring'が必要です。また、文字列リテラルに 'L 'を付ける。その後、すべてのキャストを削除します。 –
また、使用している場合は、[CreateProcess'については、[ドキュメントを読む](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx) Unicodeバージョン2番目のパラメータは文字列リテラルではなく、書き込み可能なTCHARバッファでなければなりません。 – PaulMcKenzie