Link to home
Start Free TrialLog in
Avatar of highmarks
highmarks

asked on

how to execute an .exe file(created in VC++) from C program

Hi!
I have created an .exe file using VC++6.0 with MFC Appwizard (size 560Kb)
Now I have tried executing taht exe from my c program using
execv("c:\test.exe",NULL) and also fork it gives me this error.
Debug Assertion failed expression argvector!=NULL

Can someone suggest me how to execute this.
Thanks.

Avatar of laeuchli
laeuchli

well, change execv("c:\test.exe",NULL)
to execv("c:\\test.exe",NULL) you need to '\' to make it work. If this doesn't help you will have to post more of your code.
Avatar of highmarks

ASKER

HI!
I have tried that too but does not work.
Actually I have written a code for systray icon when I double click that icon exe should run.
Now it's giving me error of c:\sample....invalid path??????
// You need more than one argument in last variable of execv,
// but last arguement needs to be null.

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


void main(){
      char *args[3],pn[50];
      args[0] = "whatever";
      args[1] = "blah blah";
      args[2] = NULL;
      printf("     Enter executable's path: ");
      gets(pn);
      int x = execv(/*"c:\\temp\\name.exe"*/pn,args) ;
      printf("\n     execv output error # %d\n\n     ",x);
      }

// If you want to do this in assembly got to:
// http://www.geocities.com/freehafer/pl2.html#EXEC
// IF YOU HAD TO EXECUTE THE FOLLOWING PROGRAM:
#include "stdio.h"//printf
#include "windows.h"//toupper BYTE

void main(int argc, char **argv)
{
      printf("The character entered is: %c!",argv[1][0]);
      printf("\nIts integral representation is: %i!",int((toupper(argv[1][0])-'A') +1));
      printf("\nIts upper case character representation after conversion from byte is: %c!",'A' + BYTE((toupper(argv[1][0])-'A') +1) - 1);
}

// YOU WOULD WRITE:
//  name.exe a
// AT THE COMMAND LINE TO OUTPUT a 1 A
// BUT args[0] DOES NOT NECESSARILY HAVE TO
// BE THE PROGRAM NAME THOUGH IT USUALLY IS,
// YET args[1] HAS TO BE THE LOWER CASE a.
      #include <stdio.h>
                #include <process.h>


                void main(){
                char *args[3];
                args[0] = "junk";//"c:\\temp\\x.exe";
                args[1] = "a:";
                args[2] = NULL;
                printf("     Enter executable's path: ");
                int x = execv("c:\\temp\\x.exe",args) ;
                printf("\n     execv output error # %d\n\n     ",x);
                }
Hi! All
I have got the answer regarding it is
WinExec(.....)
Thank you for your thoughtful evaluation of my answer.
Hi highmarks!!!!
 hope u got the answer
Evaluate this answers or delete these questions please
ASKER CERTIFIED SOLUTION
Avatar of amer_f
amer_f

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial