|
shell to executable |
BamBam
Member #7,499
July 2006
|
[center]I need my program to open a executable in the same directory.[/center] Thank you in advance... |
kikabo
Member #3,679
July 2003
|
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: replace_filename(buf, buf, "my.exe", sizeof(buf)); system(buf); but you probably want the chdir to read other relative filenames |
nonnus29
Member #2,606
August 2002
|
This is at least the fourth time I've posted this, I wonder what everyones working on.... |
Elverion
Member #6,239
September 2005
|
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
Member #2,579
July 2002
|
#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
Member #7,499
July 2006
|
Many thanks to you all for your help. |
|