Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 14th, 2005, 06:54 AM
Registered User
 
Join Date: Mar 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default can i run exe file from c or c++ code

can i run any exe file form c or c++ languge code

shafiq
Reply With Quote
  #2 (permalink)  
Old March 22nd, 2005, 12:47 PM
Authorized User
 
Join Date: Oct 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ealkurabi
Default

what kinda question is that?

Reply With Quote
  #3 (permalink)  
Old March 22nd, 2005, 06:52 PM
sangi
Guest
 
Posts: n/a
Default

hi ...
i really dont understand what is ur question ???
but why do u need to run a exe file using c coding ...if u want to result that exe file(if its a c/c++ coding) then u can use it as the header file in ur c program ...

ur question is incomplete ...

Reply With Quote
  #4 (permalink)  
Old March 23rd, 2005, 07:15 PM
Registered User
 
Join Date: Mar 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you mean injecting and exe file into your program?
If so then google it.

Reply With Quote
  #5 (permalink)  
Old April 7th, 2005, 01:06 PM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

system ("prog.exe");

HTH

--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com
Reply With Quote
  #6 (permalink)  
Old April 16th, 2005, 11:44 AM
Authorized User
 
Join Date: Jul 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to merediths
Default


 system("prog.exe") is great if you don't care about the input/output of the program. You might also want to look into the 'popen()' function -- popen() lets you get a file descriptor so you can read or write to the programs standard input/output. For example, you could popen('ftp.exe') and write ftp commands to it using fputs or whatever, or popen('top') and read process information from the 'top' command just like it was a file.

Regards,
Meredith Shaebanyan

Reply With Quote
  #7 (permalink)  
Old April 18th, 2005, 07:01 AM
Authorized User
 
Join Date: Mar 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi merediths

could you give me a good example on what you just said in your post!!!
This is very impressive answer you gave here, and this is perhaps just
the right thing i need!!!
But in code not words :-)
But don't be to mean with code, something simple will do just fine,
just to see how it works!
Perhaps example with "ftp.exe" would be good.

C or C++ code, it doesn't matter

greetings: icopec
from : Croatia
Reply With Quote
  #8 (permalink)  
Old April 19th, 2005, 10:08 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey Merediths,

Yah, but popen isn't part of ANSI C, and shafiq (I'm guessing) is on a windoze system. I'm not sure if windows supports popen(), as you're essentially opening a UNIX pipe. Anyhow, here's a bit of demo code. Works on Linux, YMMV.

/*
 * Purpose: Program to demonstrate the popen function.
 *
 * to do: Check that the 'popen' was successfull.
 *
 * Author: M J Leslie.
 * Date: 08-Jan-94
*/

#include <stdio.h>

main()
{
  FILE *fp;
  char line[130]; /* line of data from unix command*/

  fp = popen("ls -l", "r"); /* Issue the command. */

                    /* Read a line */
  while ( fgets( line, sizeof line, fp))
  {
    printf("%s", line);
  }
  pclose(fp);
}

HTH

--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
run .exe in asp hostxxi Classic ASP Basics 0 June 18th, 2008 04:01 AM
How can i code to download an exe file??? RinoDM HTML Code Clinic 1 May 25th, 2008 05:16 PM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
how to run exe file from ASP? Andraw Classic ASP Basics 1 September 23rd, 2005 06:32 AM
Run an exe julesmel C# 1 August 6th, 2003 10:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.