Thread: opening a file help

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    15

    opening a file help

    i have an exe file (a command line program) that i want to open up when a user types in go or something. where would i put the exe file and how should i write the code?

    thnx

  2. #2
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    For windows try:
    Code:
    WinExec("C:\\prog.exe",SW_SHOW);
    Have to include windows.h for that. Another way without including windows.h is:
    Code:
    system("C:\\prog.exe");
    Have to include stdlib.h for that.
    Last edited by jmd15; 09-26-2005 at 06:27 PM.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    That should be "C:\\prog.exe" in jmd15's examples.

    You could put the exe in the same directory as your program's exe. Then you wouldn't have to specify a path to it, you just pass the exe name.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    15
    thnx guys it worked!

  5. #5
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Win32 SDK FAQ - Processes: How can I start a process?

    * 'system()' family (C run-time library - ANSI ('system()') or Win NT ('_wsystem()'))
    * '_exec()' family (C run-time library - Win 95, Win NT)
    * '_spawn()' family (C run-time library - Win 95, Win NT)
    * 'WinExec()' (Win32 API)
    * 'ShellExecute()' (Shell API)
    * 'ShellExecuteEx()' (Shell API)
    * 'CreateProcess()' (Win32 API)
    * 'CreateProcessAsUser()' (Win32 API)
    * 'CreateProcessWithLogonW()' (Win32 API)
    >> Note that 'WinExec()' is provided only for compatibility with 16-bit Windows and should not be used any longer

    And system is probably less prefered, as the alternate _exec/_spawn are there for portability, no real need to fire up a command shell to start up a process.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    15
    thnx for the help guts it works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM