Tag: createprocess

如何使用createprocess在PATH中执行adb程序?

我已将adb位置添加到PATH中 。 在我的C项目中,我想执行流动的cmd: char *broadcastStop = “adb shell am broadcast -a NotifyServiceStop”; char *forward = “adb forward tcp:12582 tcp:10086”; char *broadcastStart = “adb shell am broadcast -a NotifyServiceStart”; 我可以使用system()运行上面的代码。 现在我想运行那些隐藏控制台的人。 我发现了很多类似的问题,并告诉CreateProcess可以做到。 这是我的代码: void system_hide(char *cmd) { STARTUPINFOW si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); if (CreateProcessW(NULL, cmd, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, […]

通过CreateProcess启动时,cl.exe似乎没有写入权限

我正在调用CreateProcess来启动cl.exe(Win7 64位上的VS2010)。 我收到以下错误.. cl:命令行错误D8037:无法创建临时il文件; 清除旧的il文件的临时目录 在cmd窗口中使用相同的环境变量调用相同的命令行会成功。 我检查了临时目录,没有旧文件。 似乎创建的进程没有写入权限。 我一直在尝试不同的方法.. CreateProcessAsUser,设置安全属性以授予Everyone用户组的所有标准权限,包括和不包含inheritance句柄等。它们似乎都没有解决它。 这是基本代码…… SECURITY_ATTRIBUTES sa; sa.nLength = sizeof( SECURITY_ATTRIBUTES ); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; const char* _szSourceFile = “c:\\temp\\test\\src\\foo.cpp”; char szOptions[ 2048 ]; sprintf_s( szOptions, “c:\\temp\\compile\\cl.exe ” “/Gd ” “/Fo\”c:\\temp\\test\\out\\\” ” “/Fe\”c:\\temp\\test\\out\\\” ” “/Fd\”c:\\temp\\test\\out\\\” ” “/D \”WIN32\” ” “/D \”_DEBUG\” ” “/D \”_WINDOWS\” ” “/D […]

如何使用C语言传递输入并将输出检索到子进程

我在Windows中有一个exe程序,终端的工作原理如下 > program.exe parameter01 file entry01 (user types entry01) output01 entry02 (user types entry02) output02 … until the combination Ctrl+D is pressed. 我需要用C语言创建一个“子进程”,它能够运行程序并将条目发送到“子进程”并以char []或字符串forms接收输出。 我知道我必须使用CreateProcess方法,但我不知道如何传递输入之类的条目并检索输出,我该怎么做? 我用Java看过这个,但我需要用C语言实现这个function。

在调试器下运行时,AssignProcessToJobObject失败并显示“Access Denied”错误

您执行AssignProcessToJobObject并且它失败并显示“拒绝访问”,但仅当您在调试器中运行时才会失败。 为什么是这样?

如何将argv转换为CreateProcess的lpCommandLine参数?

我想编写一个启动另一个应用程序的应用程序。 像这样: # This will launch another_app.exe my_app.exe another_app.exe # This will launch another_app.exe with arg1, arg and arg3 arguments my_app.exe another_app.exe arg1 arg2 arg3 这里的问题是我在我的main函数中得到char* argv[] ,但是我需要将它合并到LPTSTR以便将它传递给CreateProcess 。 有一个GetCommandLine函数,但我无法使用它,因为我从Linux移植代码并绑定到argc/argv (否则,对我来说这是一个非常难看的黑客)。 我无法轻易地手动合并参数,因为argv[i]可能包含空格。 基本上,我想要CommandLineToArgvW的反向。 有没有标准的方法来做到这一点?

CreateProcess()因访问冲突而失败

我的目标是在我的程序中执行外部可执行文件。 首先,我使用了system()函数,但我不希望向用户看到控制台。 所以,我搜索了一下,发现了CreateProcess()函数。 但是,当我尝试将参数传递给它时,我不知道为什么,它失败了。 我从MSDN中获取了这段代码,并稍作改动: #include #include #include void _tmain( int argc, TCHAR *argv[] ) { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); /* if( argc != 2 ) { printf(“Usage: %s [cmdline]\n”, argv[0]); return; } */ // Start the child process. if( !CreateProcess( NULL, // No […]