views:

311

answers:

3

I want to compile a batch file into an EXE file using C++. I can get through parsing the batch file and writing a new .cpp file. But I don't know how to compile the new .cpp file into an EXE file for the end user.

OK, here's the thing, I am creating an application in DevC++ that will read in a batch file. Then, one by one parsing it using:

system(getline(myfile,line));

After setting everything up, I save the newly created file as "main.cpp".

The problem is, I want to compile it into an EXE file, from my program, for the end user.

So basically, can I compile a C++ file from a C++ EXE?

+3  A: 

The short answer is no. Unless you are willing to write an entire C++ compiler, you will need to invoke an external C++ compiler to compile that .cpp file.

On the plus side, if you are simply looking to convert .BAT files into .EXE files, there are several existing solutions, such as quickbfc.

e.James
+1 for an imaginative response
Liz Albin
+4  A: 

Yes, you can provided that the end user has a C++ compiler installed and you're emitting valid C++.

Depending on the compiler you're using, your C++ executable would have to spawn a process that runs

cl main.cpp

or a similar invocation of the compiler after finishing the translation.

If your user doesn't have a compiler installed, then you're pretty much out of luck - trying to build a C++ compiler yourself is a rather non-trivial exercise.

Timo Geusch
A: 

Can I ask why do you need to parse bat file?

I mean if you are taking input or something from that file then can you try to use a database or something for that?

Also for the user end you can write web application to display output. There`s C++ Server Pages equivalent to JSP, PHP which can use C++ classes.

Am I helping here or this is not what you want? may be if you can describe you application use somebody can help you better.

Amol Joshi