Connecting Tech Pros Worldwide Help | Site Map

execute a .exe file using turbo c++ program

Newbie
 
Join Date: Apr 2007
Posts: 4
#1: Apr 4 '07
how can an already existing exe file say <filename.exe> be executed using a turbo c++ program....
i have tried

system(" path of file");

but it always returning an error i.e. the integer value it returns is -1.

help me .... its urgent
sicarie's Avatar
Moderator
 
Join Date: Nov 2006
Location: USA
Posts: 3,929
#2: Apr 4 '07

re: execute a .exe file using turbo c++ program


Quote:

Originally Posted by abhisheknaina

how can an already existing exe file say <filename.exe> be executed using a turbo c++ program....
i have tried

system(" path of file");

but it always returning an error i.e. the integer value it returns is -1.

help me .... its urgent

Did you try backwhacking the path to the file? ie - using double backslashes instead of single?

C:\Windows\ -> C:\\Windows\\
Newbie
 
Join Date: Apr 2007
Posts: 4
#3: Apr 4 '07

re: execute a .exe file using turbo c++ program


yeah ..
i tried it but its still giving the error ..i.e. output -1

my exe file was developed through turbo c++ itself
sicarie's Avatar
Moderator
 
Join Date: Nov 2006
Location: USA
Posts: 3,929
#4: Apr 4 '07

re: execute a .exe file using turbo c++ program


Quote:

Originally Posted by abhisheknaina

yeah ..
i tried it but its still giving the error ..i.e. output -1

my exe file was developed through turbo c++ itself

Can I see the system() call you're using?
Newbie
 
Join Date: Apr 2007
Posts: 4
#5: Apr 4 '07

re: execute a .exe file using turbo c++ program


my program was


main() {
int i;
i = system("c:\\turboc3\\sim.exe");

cout<< i;
}
Newbie
 
Join Date: Apr 2007
Posts: 4
#6: Apr 4 '07

re: execute a .exe file using turbo c++ program


how about using spawnl()???

but i donno its format..
help me out guys
sicarie's Avatar
Moderator
 
Join Date: Nov 2006
Location: USA
Posts: 3,929
#7: Apr 4 '07

re: execute a .exe file using turbo c++ program


Quote:

Originally Posted by abhisheknaina

how about using spawnl()???

but i donno its format..
help me out guys

Yeah, I don't know - that code works on my compiler...
Newbie
 
Join Date: Jul 2009
Posts: 1
#8: Jul 13 '09

re: execute a .exe file using turbo c++ program


U can use any of the following two method:

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<process.h>
  3.  
  4. int main()
  5. {
  6.     int c = execl("C:\\TC\\BIN\\SU.EXE", NULL);
  7.  
  8.     printf("%d",c);
  9.     return 0;
  10. }
  11.  
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<process.h>
  3.  
  4. int main()
  5. {
  6.     int c = spawnl(P_OVERLAY, "C:\\TC\\BIN\\MM.EXE", NULL);
  7.  
  8.     printf("%d",c);
  9.  
  10.     return 0;
  11. }
  12.  
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#9: Jul 13 '09

re: execute a .exe file using turbo c++ program


@oscse: please don't wake up threads that are long dead (see the posting dates). btw, I removed the bold tags and added code tags for readability.

kind regards,

Jos (moderator)
Reply