shell to executable
BamBam

[center]I need my program to open a executable in the same directory.[/center]
How can i do this. I am running windows xp and
using mingw32 and allegro. Some source code would be
nice.

Thank you in advance...

kikabo

One way is to change to that directory and the execute the executable. There's probably a nicer way but this should work (I think) :-

char buf[200];

get_executable_name(buf, sizeof(buf));   // get the app full path
replace_filename(buf, buf, "", sizeof(buf)); // strip everything but the path
chdir(buf);
system("my.exe"); // or shell_exec("my.exe");

edit:
or just

replace_filename(buf, buf, "my.exe", sizeof(buf));
system(buf);

but you probably want the chdir to read other relative filenames

nonnus29

This is at least the fourth time I've posted this, I wonder what everyones working on.... :P

Elverion

Or #include <windows.h> and do this:

ShellExecute(NULL, "open", "c:/path_to_exe/program.exe", NULL, "c:/path_to_execute_from/", SW_SHOWNORMAL);

You should use get_executable_name for the full path (3rd argument), and a combination of get_executable_name and replace_filename for the path to execute from (5th argument) to work as I expect you want it to. See kikabo's post for that.

You could also use WinExec("path", SW_SHOWNORMAL) if you do not need it to be executed from the path. I still recommend ShellExecute, though.

Goalie Ca
#include <stdlib.h>

int main(int argc, char** argv)
{
 if (argc != 2)
    return EXIT_FAILURE;

  system(argv[1]) ; //file name to execute (relative to the "working"directory aka this directory...
 // see also exec() etc. 
}

BamBam

Many thanks to you all for your help.
Problem solved...

Thread #586546. Printed from Allegro.cc