Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 14th, 2005, 06:54 AM
Registered User
 
Join Date: Mar 2005
Location: Lahore, punjab, Pakistan.
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
Location: , NY, USA.
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
Authorized User
 
Join Date: Jan 2005
Location: Magdeburg, Saxony Anhalt, Germany.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
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
Location: , , .
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
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
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
Location: , , .
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
Location: Zagreb, , Croatia.
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
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
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
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:08 PM.


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