createProcess 呼叫命令行工具
CreateProcess + Call command line tool
我对线程和流程的新手很新,我发现即使还有很多其他论坛帖子,我也无法让createProcess()启动可执行文件。从我认为我认为我的参数设置正确的微不足道,但我会收到Create Process failed (267)
错误。我试图运行的可执行文件是属于Xilinx套件的命令行工具,称为XST。我想要的是在由path
Global变量定义的目录中运行XST,以便它可以在存储在其中的某些文件上。我是否有createProcess()错误的参数?
#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设置的环境变量,以便我可以在命令行中的任何地方称呼它
这里有几个问题。
首先,正如@paulmckenzie在评论中指出的那样,lpCommandLine
参数的类型是LPTSTR
,而不是LPCTSTR
。因此,您无法传递std::string::c_str()
的返回值,因为那会返回const缓冲区。您需要将std::string
的内容复制到char
数组中,然后将其传递给CreateProcess()
。
其次,您没有传递lpCommandLine
参数的正确值。它的值不是该过程的参数,而是要执行的整个命令行。除了任何参数外,这还必须包括通往可执行文件的路径。将其视为您将在命令提示下运行同一件事的键入的内容。
相关文章:
- 选择特定版本的 Visual Studio 命令行工具包,并根据特定版本的C++运行时环境编译文件
- 如何通过命令行工具在 COIN-OR Cbc 中设置超时?
- createProcess 呼叫命令行工具
- 在应用程序内部调用linux命令行工具
- CMake命令行定义不永久为工具链文件
- MAC c++ 控制交互式命令行工具
- 更新 OSX 命令行工具 6.3 后缺少C++标头<__debug>
- 基于Qt的OpenGL上下文命令行工具
- 是否可以将依赖项嵌入到命令行工具中
- 使用 VS2010 的 msbuild 构建时,我可以从命令行设置平台工具集吗?
- 允许命令行工具使用 ofstream 创建文件
- 如何从 system() 使用 Visual Studio 2012 命令行工具
- 如何将命令行工具包装到应用中并正确退出它
- 如何在C++应用程序中使用GnuPG(不像命令行工具那样)
- 简单的HowTo在调试器中启动OSX上的C++命令行工具
- 使用Objective-C/C静态库进行c++命令行工具项目
- 无法用Visual Studio 2015命令行工具编译和链接简单的c++程序
- 在xcode中将命令行工具转换为.app
- 这是命令行工具的最佳设计
- 将GUI附加到命令行工具