在程序中运行程序,两次
C++ Run program within program, twice
我正在努力开发一个系统,使我能够编译一个可以运行我制作的其他程序的。exe。现在,它可以,但它只能运行一次外部程序。一切运行在一个cmd窗口。我输入一个命令,它执行操作(运行一个单独的.exe),然后等待第二个操作。
我会尽量简化我正在做的事情。
正在运行的。exe。我们把它命名为TheCauser.exe
int main()
{
.
.
.
if(stuff is met)
{
.
.
.
system(foundtextchar);//Windows run program
cout << endl;
}
}
要从上面的代码运行的。exe。命名为DoMe.exe
int main()
{
//It just does whatever
.
.
.
return 0;
}
绝对基本的。虽然事情运行顺利,我只能运行DoMe.exe,并有材料出现在cmd窗口一次。种。我在causer .exe中有一个小通知,告诉我何时DoMe.exe正在运行。当我第二次运行DoMe.exe时,通知出现了,但没有来自DoMe.exe的材料。我的假设是,一旦DoMe.exe第一次运行,它就不会真正关闭,而是继续运行。
我觉得有必要提一下,如果我想运行第二个程序,我们叫它heylisten。exe,如果dome。exe之前在运行,heylisten。exe不会显示它的材料但是会弹出通知说它正在运行。HeyListen.exe将以与DoMe.exe相同的方式构建。
我觉得如果我的问题是在DoMe.exe,在那,它没有结束它的进程的方式,我希望它做的。这是正确的吗?我怎么才能让它工作呢?
我想张贴一张cmd窗口的图片,以帮助给一个视觉,但显然我没有足够的声誉。对不起。
使用CreateProcess()
生成程序。(https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx)
示例(来自MSDN)
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
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 module name (use command line)
argv[1], // Command line
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
NULL, // Use parent's starting directory
&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 );
}
相关文章:
- 当同一个程序被打开两次时,如何使用C ++杀死一个程序?
- 基于 MFC 对话框的应用程序无法调用对话框两次
- 程序在运行两次后关闭
- C++使用二维数组的程序,该数组要求用户输入两次.它需要将这些输入显示为输出
- 阵列不能两次将相同的名称保存,当要添加新字符串时,程序应检查以查看该名称是否已经存在
- 为什么这个程序打印"nine"两次?
- 在同一程序中调用srand()两次
- 为什么这个程序中的析构函数被调用两次
- 为什么这个C++/OpenGL程序运行两次
- C++程序要求我输入两次,即使变量第一次被分配
- 我是否需要锁才能同时使用同一应用程序两次写入套接字
- 多次定义"调度程序::_singleton",导入标头两次
- 程序写入记录在 C++ 的二进制文件中两次
- c ++:TCP服务器"bind"功能失败(errno 98),如果我在两次连续应用程序启动之间没有等待足够的时间
- C++程序 尝试连续运行两次写入循环时显示".. stopped working"错误
- 为什么在这个树程序中,我得到了两次输出
- 我正在尝试递归地实现一个程序。我只是不明白为什么我的最后一行被执行了两次
- 为什么我的程序不崩溃,如果析构函数被调用两次
- 在程序中运行程序,两次
- Async_read_until处理程序被调用两次