About executable jar in eclipse - executable-jar

I was learning about making executable jars for windows in eclipse and tried to make couple of them. Purpose of the simple classes I wrote was just to make executable jar. Jars worked fine if those classes were some GUI stuff (main method executed). But, I also made even simpler class that just prints out some message, created executable jar, put it on desktop, double clicked it, but, no message was printed... What happened? why simple, message printing class didn't execute when I double clicked icon for executable jar? How can I make executable jar which will also run the message-printing part of code?

But, I also made even simpler class that just prints out some message,
if you printed those using the System.out.println() method, then you need to run the jar from a terminal like CMD or similar... there you will see it...
If you instead just double click the executable jar, the System.out.println() methods are executed but you will never see them..

Related

Making .exe file in Visual Studio 2013

I have made my project in C++ and used SFMl 2.1, I also have loaded images from disk and when I'm trying to run its .exe file its giving error in image loading.
For now I'm trying to run its own .exe fie (in Debug or Release folder of project).
i want to make this .exe file for my friends who are not programmers so that my game would run on their PCs as well.
If someone know to make .exe so please help!
First, try to put the images beside the exe file.
After that, your friends probably won't have all the development DLL and libs needed for your app to work. You can use depends.exe to know what is needed for your app to start. Put all those file beside your exe and it should work on most PCs.
Bonus tip
Often, when you experience this kind of problem (application crash when starting directly outside the project), the simplest solution, which is language-agnostic, is to make your app write to a new file within your main function and look where it ends up in your project hierarchy after you ran your app directly (outside the IDE/project).
You'll see right there where the relative root of your app is. Most of the time, it's right next to the compiled file, depending on the language you chose.

Launching a stand-alone executable from C++

I have a programmable signal generator. It came with a .inf file and a .exe file. Double clicking the .exe file runs the signal generator systems application.
I would like to invoke this executable from a piece of VC++ code. I am using Shell Execute as follows.
std::string app = "C:\gen.exe";
ShellExecute(NULL,"open",NULL,app.c_str(),NULL,SW_SHOWNORMAL);
However, instead of launching the executable, the command pops open a file dialog.
Upon further experimenting with ShellExecute, I noticed that ShellExecute works for executable files in the Program Files directory, but fails when I have stand alone executables such as in the case I mentioned above. Can someone please explain how to launch using VC++ a standalone executable located in a random directory on the disk?
By Standalone executable, I mean that the binary distribution for the application was simply an executable file, and a couple of other files. I can launch the executable by simply double clicking it, however, I cannot launch it using ShellExecute.
If you take a look at the documentation for ShellExecute (link), it seems like you might have the reference to app in the wrong parameter. The fourth parameter is the parameters parameter - not the parameter specifying which file to open/run. So basically, this should work:
std::string app = "C:\\gen.exe";
ShellExecute(NULL,"open",app.c_str(),NULL,NULL,SW_SHOWNORMAL);
Alternatively, you could use CreateProcess or system("C:\\gen.exe");. I should point out that none of these options are portable to other OSs, but running a program probably won't be, however you end up doing it, since most OSs differ on how they run programs - or even what programs are.

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

Renaming executable to game.exe causes 15 second delay when running -- STRANGE issue

This shakes my understanding of computers and operating systems on a level that makes me very uneasy. I have just spent about an hour entering different iterations of compile commands to g++ and in my exasperation I renamed the executable which kept having the delay from game.exe to gameg.exe and all of a sudden the problem vanished.
Here's some more background: I was noticing recently that when I ran my Eclipse unit test build, when I start with an SDL enabled test it would open the SDL window and freeze for about 20 seconds before being able to get the test started. On subsequent tests (which call SDL_Quit() and re-initialize SDL as part of the test process) this delay is not present. Now I have ascertained that ONLY when the executable is named exactly "game.exe" does this happen! I rename it to any other filename and it goes along running tests happily, initializing the SDL system within a second like it usually does. I had assumed before that there must be some kind of bug that was causing my Eclipse build to have this behavior which wasn't present in the makefile build, but it turns out if I take the eclipse build and rename its executable (the project folder it's in is called game hence game.exe) it doesn't exhibit the behavior.
Likewise I take my makefile build (whose filename is entropy_unittest_disp.exe fyi) and rename it to game.exe and it begins to do this. I rename it to game and it also does it (I am running from mingw's bash.. when not with .exe extension, explorer doesn't know it's an executable). However I changed it to game.exx and it worked normally.
WHAT IS THIS BLACK MAGIC? Why should a program function differently depending on its filename??? I do query argv[0] and i actually do it to print to console its value (for debug purposes) but unsurprisingly it just prints the program and its path. No logic is ever performed on it in my program.
I tried to run GDB to find out where it is freezing but once I press Ctrl+C GDB simply exits.
does anybody have any idea what this might be caused by? A virus?
edit: I downloaded this demo from this site: http://www.sdltutorials.com/sdl-opengl-tutorial-basics/
extracted it, renamed the file to game.exe, and yup, same thing happens. WHAT IS THIS? I'm going to try running dependency walker next to see if something's trying to hook into it.
I'm assuming you have either a AMD (ATI) or Nvidia graphics card with their official drivers.
Chances are, game.exe is the executable name for an actual game released and your drivers are running special optimizations for the "game" or loading the Crossfire or SLI profiles for this game. A quick Google search seems to tell me that Resident Evil 4 calls their executable "game.exe."
I recommend taking a look at this link for further details as to what may be happening:
http://www.kn00tcn.net/site/ati-catalyst-profiles/
not sure how to reply to steven's comment on the top answer, but regarding driver profiles, it's just a basic brute force check of .exe filenames
some games are guaranteed to be in a specific sub folder, so the driver looks for where the exe is located, such as '\team fortress 2\hl2.exe'
but since most games let you pick what folder name you're installing to, & a lot of the time the exe is in that same root folder, the drivers have no choice but to blindly assume gameX.exe is going to be gameX
a nice 'side effect' of this is you can force other game profiles on any game for troubleshooting purposes, or to try to enable CF/SLI scaling
so always try to make sure that your executable has an original name to know that the gfx driver isnt attempting to run 'optimizations' made exclusively for other games
Could this be due to Anti virus software running on your OS? Certain files are commonly used in Virus "Game.exe" could be one of them and hence additional care from OS / AV to ensure that it is safe
Test it in clean windows, without any extra software installation, if it work fine, then maybe you have some protection software like Anti-virus or sandbox , ... , if you have any of this software disable them, and test again
Check to see if game.exe is listed in the Image File Execution Options registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options. It can be used to launch a particular program as a debugger for an application with a particular name. (More info on Image File Execution Options)
An EXE will behave differently based on its name due to AppCompat Shimming. Check the loaded module list and see if there are a bunch of DLLs that start with "ac" loaded into your app.

How to incorporate this script into build process using VC++

I'm using VC++ and want to write a script that can scan my source-code and at some places where it sees a text like "abc" then extract characters of that text and generate a selective piece of code like ones below at build time:
first example of a piece of code :
Func1(a);
Func2(b);
Func3(c);
second example of a piece of code:
{'a','b','c'}
I want to incorporate the script into build process as somebody has told me it is possible but don't know how, please tell how.
In the project properties of Visual Studio, you will have the option "Pre-Build Event" and "Post-Build Event".
At these configurations you can input programs that should be executed before and after your build. You can use project variables to identify your solution folder, project folder, binary, etc. If you are using a recent version of Visual Studio, there is a button below the text box that give you access to those variables.
Make sure that whatever you call at this configuration would be executed from the shell environment (cmd), otherwise you will receive a build error. Scripts will probably required that you input a call to the interpreter and pass the file as a parameter.
For example, let's say I need to run a Python script before I build my code. I would configure the Pre-Build Event as:
c:\python\python myscript.py
One good advice is to use DOS Batch files (.bat) to wrap around whatever you need to run and add those to your build events. There are plenty of tutorials over the net on how to create bat files, and they are fairly simple.