Compile batch file into an EXE file - c++

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?

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.

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.

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.

Related

Access Path Of File In C++

I want to access the path of the executable file. I know in python, you can do the following:
import os
filePath, fileName = os.path.split(__file__)
The code above will get the path of the file, and the name of the file that the lines are in. Is this applicable in C++ (returning the name is more optional)? I do NOT want the source code, only the path of the executable.
PS: if you think this is very little detail, copy paste the code above, paste the following:
print(filePath)
and run the code in a python intepreter.
PPS: Tried installing POCO or qt, as one of the comments in the first question mentioned, and didn't find out how to install.
PPPS: For more details of why I want the path and what I'm doing it with: I need the path so I can load assets to a game. Sometimes, the program just won't load the image after putting in the name of the file, like other people in tutorials do (albeit the image file is in the same directory). And then I figured out that for python, the code above works, so I'm asking if this is applicable in C++.
In Python, you're getting the path to the file containing the source code that's executing.
In C++, the file containing the source code to what's executing may not exist, or (more often) may exist but be inaccessible (e.g., stored on a system to which you don't have access).
Instead, in C++ the source code is normally compiled to an executable file, and that's what runs. But that executable contains machine-level instructions rather than the C++ source code of the program as the programmer wrote it.
If you want access to the source code at run time, you're almost certainly going to have to do that on your own--make sure a copy of the source code is on the target computer in some location you can find.
The C++ standard library contains basic support for things like searching for a particular file in a file system tree, but it's going to be up to you to put those building blocks together into a system that gives you access to the source code at run-time. Chances are pretty good that in the process, you'll end up needing a few things that are available on most operating systems, but still require code specific to the operating system you're using (e.g., getting the path to the executable file so you can build some path relative to that where you store the source file).

What do I need to do to compile a C++ program with Embarcado XE7?

I'm trying my first program in this particular environment and it seems unnecessarily complicated.
I've written a header file xxxx.h and a C++ file xxxx.cpp but there doesn't appear to be an option to compile this (where I would expect it to be in the toolbar, the run and/or compile options are greyed out and unavailable).
What am I doing wrong? Maybe I haven't saved these files in the right place or I don't know where they should have been written/created.
I know nothing about this compiler/editor so there may be loads of things that are obvious to an experienced programmer which I'm just not aware of. Do the .h and .cpp files need to be part of a project which ultimately gets compiled? If so, how do I make these files part of that project?
I feel like I couldn't even write a "Hello World" program in this environment with my current knowledge. Please help.
The IDE(Environment) might require you to make it a project type. If you can't find help or instructions in the program itself, please try the following:
select file, then new. In the drop down box, select project and just read through whatever comes up and click OK. Now, you might already have a .cpp file opened by default. If you do, you are lucky, just type your code in, and you will be able to compile it. Otherwise you have to make a new .cpp file within the project using the project window.
Please bear in mind that I'm saying this with experience only form similar IDEs, not your particular one. If you are a beginner, then probably Borland C++ IDE will be better for you. Not the embarcadero one, the older versions used in the 1998-99 period. Hope this helps. Thanks.

Adding a text file to an exe generated by PyInstaller

I have a rather interesting problem I've been trying to find a way to solve, and as of the moment, I have not found a solution to. I currently have built a GUI program using Python, and more specifically using Tkinter, which will generate a file with a list of commands to be repeated by my program in the specified order while waiting however long is specified. It's basically used to create a macro, which is recorded in a file and can be ran later using another function in the program.
What I would like to add to my program is a manner in which to create an .exe file, which is a standalone file, that can run a script from within it. The reason I can not find a good way to do this though is because I need for it to be created on the fly. What I was thinking I'd like to do is generate an .exe(Standalone macro exe) with PyInstaller ahead of time, and package this in to my main .exe also using PyInstaller. When you choose the option to create a standalone macro, it would proceed to get the .exe(Standalone macro exe) which I had packaged in to my main .exe from the directory in which it was unpacked in to when the program was run, copy it to the desired location for the standalone exe to be saved to, and then copy the script the user wished to be run as a standalone and package it in to the standalone exe.
I have no idea how to go about this, because I'm not sure exactly how PyInstaller puts the files in to a .exe when it packages it. Because of that, I wouldn't know how to add a file to an existing .exe using python.
Basically what I need help with is how I might go about adding a text file to an .exe generated by PyInstaller.
Ummm,
Could you clarify something...are you thinking something like Perl's (25th birthday today) (camel book by Larry Wall, p44) handles or a Bash HERE document ?
Update (based on discussion below): This will integrate python files and other externalities into a single installable:
http://www.pyinstaller.org/export/d3398dd79b68901ae1edd761f3fe0f4ff19cfb1a/project/doc/Manual.html?format=raw#create-a-spec-file-for-your-project
http://www.pyinstaller.org/export/d3398dd79b68901ae1edd761f3fe0f4ff19cfb1a/project/doc/images/SE_exe.png

How to build midas.obj from the midas source code

Recently I discovered a problem on the midas and I fixed it, the problem now is that I want to use MidasLib not the midas.dll and with the source code I'm only able to build the DLL.
The source is C++ and I have very few knowledge with it. I know the MidasLib.pas uses internally midas.obj, so I need to create it to statically link the midas to my application. How to do it on C++ Builder? (XE)
When you compile C++ code, the compiler creates an .OBJ file for each .CPP/.C file you have and saves them somewhere on your computer. What happens in most cases is that one would run a linker on all of those .OBJ files to join them into a single EXE or DLL, but in your case you don't need those results. Your C++ Builder is, like most programming IDEs, automatically doing both the compilation and linking.
If you just want the .OBJ, you need to find where in your project folder C++ Builder is placing its .OBJ files (called its "intermediate output", typically, as it is the intermediate step between compilation and linking). So you must have a source file called midas.cpp or midas.c that produces a corresponding output file called midas.obj.

Generate executable file at runtime - C++ / Visual C++

Maybe you can help me with a question I have, related to C++ language:
Is it possible or, is there a way to generate an executable file at runtime of a C++ Windows application?
To illustrate you why I'm asking this, I will detail the scenario that I'm thinking right now:
I have a C++ Windows Application that is more like an editor, where the user inputs some data and make some configurations, so when everything is done, the user clicks the "Run" button and this editor based on the user input data and configurations, creates some C++ or C# code files, compiles them and generates an executable file that the user can simply use without having to enter any line of code by himself.
Is it possible? Please can you give me a clue of how to do my search or where to find some help?
Of course it is possible, the compiler itself is likely a program that fulfils this requirement.
If you want to do it without just invoking a compiler though (and thus generate source code to feed it), you need to learn quite a bit about the machine language and executable file format of your platform.
You could simply make a call from your application to an external compiler, make the compiler build your executable and if the compilation is successful you could run the resulting executable. You can even capture the output of the compiler in your application.