求助::有人知道这是为什么吗??

bingyifeng_1985 2006-08-14 04:23:57
#include <windows.h>
#include <iostream.h>
#include <process.h>
void main()
{
while(1)
{
char argc[100]="x";
execl("C:/Program Files/gs/Login.exe",argc,NULL);
cout<<"sssssss"<<endl;
}
}
运行程序后竟然没有任何输出,只是运行了Login.exe
为什么不往后执行啊
怎样做才能保证输出语句得到执行呢??
还有当我用system("C:/Program Files/gs/Login.exe")时竟然不能识别空格
这时候该怎么办啊??
...全文
231 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
bingyifeng_1985 2006-08-20
  • 打赏
  • 举报
回复
回去试试
谢谢大家了啊
lddLinan 2006-08-15
  • 打赏
  • 举报
回复
create a child process for "login.exe" and wait for child process's termination in parent process. Thread is not an alternative solution because of the usage of execl.
bingyifeng_1985 2006-08-15
  • 打赏
  • 举报
回复
如果我想继续往下执行
有解决的办法没有??
jixingzhong 2006-08-15
  • 打赏
  • 举报
回复
execl("C:/Program Files/gs/Login.exe",argc,NULL);
==》
spawnl(P_WAIT, ...) //...代表的参数和 execl 函数参数一致

spawn 也是启动进程,
但是它可以通过第一个 mode 参数控制运行模式,
P_WAIT 表示在新进程运行结束后回到当前进程继续运行 ...
jixingzhong 2006-08-15
  • 打赏
  • 举报
回复
exec 函数族,
启动新的进程后,
会结束当前的进程 ...

所以后面的代码自然就没有运行了 ...
0黄瓜0 2006-08-14
  • 打赏
  • 举报
回复
msdn:
If successful, these functions do not return to the calling process.
sinall 2006-08-14
  • 打赏
  • 举报
回复
Example

/* EXEC.C illustrates the different versions of exec including:
* _execl _execle _execlp _execlpe
* _execv _execve _execvp _execvpe
*
* Although EXEC.C can exec any program, you can verify how
* different versions handle arguments and environment by
* compiling and specifying the sample program ARGS.C. See
* SPAWN.C for examples of the similar spawn functions.
*/

#include <stdio.h>
#include <conio.h>
#include <process.h>

char *my_env[] = /* Environment for exec?e */
{
"THIS=environment will be",
"PASSED=to new process by",
"the EXEC=functions",
NULL
};

void main()
{
char *args[4], prog[80];
int ch;

printf( "Enter name of program to exec: " );
gets( prog );
printf( " 1. _execl 2. _execle 3. _execlp 4. _execlpe\n" );
printf( " 5. _execv 6. _execve 7. _execvp 8. _execvpe\n" );
printf( "Type a number from 1 to 8 (or 0 to quit): " );
ch = _getche();
if( (ch < '1') || (ch > '8') )
exit( 1 );
printf( "\n\n" );

/* Arguments for _execv? */
args[0] = prog;
args[1] = "exec??";
args[2] = "two";
args[3] = NULL;

switch( ch )
{
case '1':
_execl( prog, prog, "_execl", "two", NULL );
break;
case '2':
_execle( prog, prog, "_execle", "two", NULL, my_env );
break;
case '3':
_execlp( prog, prog, "_execlp", "two", NULL );
break;
case '4':
_execlpe( prog, prog, "_execlpe", "two", NULL, my_env );
break;
case '5':
_execv( prog, args );
break;
case '6':
_execve( prog, args, my_env );
break;
case '7':
_execvp( prog, args );
break;
case '8':
_execvpe( prog, args, my_env );
break;
default:
break;
}

/* This point is reached only if exec fails. */
printf( "\nProcess was not execed." );
exit( 0 );
}

adintr 2006-08-14
  • 打赏
  • 举报
回复
system("\"C:\\Program Files\\gs\\Login.exe\"")

64,631

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧