PDA

Click to See Complete Forum and Search --> : A Question for all


AbhishekD
October 21st, 2004, 07:18 AM
Hi!
I want to make a program in C or C++ which can run a .bat file from the folder in which the program is stored.

How can i make that file execute from the c program.

The problem is that how can i get to know from the program itself that where the user has stored the file without requesting the user to store it in a particular folder.

el-half
October 22nd, 2004, 04:42 PM
#include <stdio.h>

int main() {
system("Phile"); //where Phile is the .bat file

return 0;
}

You mean, searching for a file? You could write a function for that, or use some already available library...

AbhishekD
October 23rd, 2004, 09:15 AM
Hi!
I exactly want to know that after the execution of the .bat file will control return to the next line in c program or to the dos prompt.
If to the c program then can another file be executed likewise.

How can the file be searched in folders and subfolders??????????

Please reply soon

el-half
October 23rd, 2004, 02:19 PM
It returns control to the C program, in the previous example the only thing left to do was exit so...

#include <stdio.h>

int main() {
system("Phile");
printf("First batch file executed");
system("OtherPhile");
printf("Another file executed");
getch(); //leet pause

return 0;
}


I don't know a good way to search for a file in all directories.
Maybe you could execute a system("dir /AD > dir.txt");
And then read all directories from the dir.txt file into an array or something and use that...
Maybe it is possible in C to read system() output, in Java at least this is possible, my knowledge in C is very limited though in such things.
From a design point of view it would be better of course not to use the method I just mentioned, it should possible to implement this in C relatively uncomplicated.