我应该怎么做才能使用新的命令提示符窗口获取新进程?
我有两个控制台应用程序,第一个运行第二个:
1_first 控制台应用程序:
#include <Tchar.h>
#include <windows.h>
#include <iostream>
using namespace std;
void main(){
PROCESS_INFORMATION obj1;
memset(&obj1,0,sizeof(PROCESS_INFORMATION));
STARTUPINFOW obj2;
memset(&obj2,0,sizeof(STARTUPINFOW));
obj2.cb=sizeof(STARTUPINFOW);
CreateProcessW(_TEXT("c:\\runme.exe"),_TEXT("hello what's up?"),NULL,NULL,FALSE,NULL,NULL,NULL,&obj2,&obj1);
}
2_second 名为 runme.exe 的控制台应用程序:
#include <stdio.h>
#include <iostream>
using namespace std;
int main(int argc,char * * argv){
if (argc>0)
for (int i=0;i<argc;i++)
cout <<"**->**"<<argv[i]<<"\n";
}
现在我的问题是这两个应用程序都将使用相同的命令提示符窗口,我应该怎么做才能让它们使用单独的命令提示符窗口?
I got two console applications that the first one runs the second one:
1_first console application:
#include <Tchar.h>
#include <windows.h>
#include <iostream>
using namespace std;
void main(){
PROCESS_INFORMATION obj1;
memset(&obj1,0,sizeof(PROCESS_INFORMATION));
STARTUPINFOW obj2;
memset(&obj2,0,sizeof(STARTUPINFOW));
obj2.cb=sizeof(STARTUPINFOW);
CreateProcessW(_TEXT("c:\\runme.exe"),_TEXT("hello what's up?"),NULL,NULL,FALSE,NULL,NULL,NULL,&obj2,&obj1);
}
2_second console application named runme.exe:
#include <stdio.h>
#include <iostream>
using namespace std;
int main(int argc,char * * argv){
if (argc>0)
for (int i=0;i<argc;i++)
cout <<"**->**"<<argv[i]<<"\n";
}
Now my problem is that both applications will use the same command prompt window, what should I do to get them using separate ones ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您调用
CreateProcess
时,在进程创建标志(第六个参数)中传递CREATE_NEW_CONSOLE
。当您调用
CreateProcessW
时,您不想想要在字符串上使用_TEXT
。CreateProcessW
始终采用宽字符串,因此您应始终在它们上使用L
前缀。_TEXT
(或_T
)仅与CreateProcess
一起使用(无后缀),因此它可以从窄根据您是否定义 UNICODE/_UNICODE 来转换为宽字符串。Pass
CREATE_NEW_CONSOLE
in the process creation flags (sixth parameter) when you callCreateProcess
.When you call
CreateProcessW
you do not want to use_TEXT
on strings.CreateProcessW
always takes wide strings, so you should always use anL
prefix on them._TEXT
(or_T
) is only for use withCreateProcess
(no suffix), so it can change from narrow to wide strings based on whether you define UNICODE/_UNICODE.