I have a python script that handles running my unit tests for Eclipse:
Imports projects to a workspace
Builds the project
Runs the Executable
Here is a Gist of my Python script
The cibuild_tests.bat referenced in the script does this:
set eclipse_dir=%1
set workspace_dir=%2
set project_dir=%3
set name=%4
set config=%5
%eclipse_dir% -nosplash --launcher.suppressErrors -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data %workspace_dir% -import %project_dir% -cleanBuild "%name%/%config%"
This all runs perfectly fine, the problem is when subprocess.call(ex) is called in run_executable(...). The output from that executable is never displayed in the console. The output is displayed when the batch script is run for building the project from Eclipse. The executable is a Google Test build and i have it set to output an XML file of the results. I can find no record of the file being created anywhere leading me to believe it is never being run.
But my check to see if the executable exists do find the executable so it is present.
Everything runs just as i expect on my local machine.
Question: What prevents the second subprocess call from outputting to the console, or running, in Jenkins but the first one has no issues?
So i remoted in to the computer and found the issue. It seems a window was popping up reporting a missing DLL for my run process. Once i ensured the DLL was available the error went away and everything built.
Related
I'm asking help today because I'm new to Tkinter and Pyinstaller (and python in general) and I'm having troubles with it.
I have a simple app working with sqlite, tkinter and pyinstaller to compile all of this in an executable program, the entrance point of my program is a file named main.py
This file calls all the dependancies (like the sqlite module for python, tkinter and my other files like classes etc...)
I made a very simple interface, with a Hello World in a tkinter label and a button to go to page 2 which displays page2 (also in a label), just to see if I'm capable of making it all run and compile all of these pieces together.
I can run it throught my shell executing it like : python main.py and everything is working fine.
But when I run pyinstaller on my linux machine, and start executing the program, nothing appears, my database.db (sqlite database file) is created but I don't have any interface like when I run it with my shell. The thing is getting even worse on windows where, once I've my .exe it just opens a shell and crash after few seconds, not even creating the database.
What I did is I created a 'log file', in which I write the steps of the program.
As you can see on the following picture, the 2 first prints are wrote in my log file (on linux), so I think it crashes when I try to create the window.
If any of you have an idea on what I do wrong, I would really appreciate help :)
General
From the PyInstaller manual:
Before you attempt to bundle to one file, make sure your app works correctly when bundled to one folder. It is is much easier to diagnose problems in one-folder mode.
As the comments suggested, use a catch-all try/except block to log all exceptions to a file. That is probably the best way to see what is really happening. Make sure that the logfile is created in an existing location where you have the necessary permissions.
I would suggest to take advantage of the built-in logging module instead of creating your own. It can e.g. automatically add from which file a log line was created.
IMHO, it is probable that the failures on Linux and ms-windows have completely different causes. You should probably treat them as different issues.
Linux
When you use single file mode, that file is unpacked into a temporary folder, probably somewhere in /tmp. Some Linux distributions mount the /tmp filesystem with the noexec flag. This is incompatible with PyInstaller.
ms-windows
On windows, there are basically two different Pythons; python.exe and pythonw.exe. Basically it is one of the quirks of windows that this is necessary. The latter is for GUI programs like tkinter programs. A tkinter script should not show a cmd window. So I'm guessing that PyInstaller calls your command with python.exe instead of pythonw.exe. From the manual:
By default the bootloader creates a command-line console (a terminal window in GNU/Linux and Mac OS, a command window in Windows). It gives this window to the Python interpreter for its standard input and output. Your script’s use of print and input() are directed here. Error messages from Python and default logging output also appear in the console window.
An option for Windows and Mac OS is to tell PyInstaller to not provide a console window. The bootloader starts Python with no target for standard output or input. Do this when your script has a graphical interface for user input and can properly report its own diagnostics.
As noted in the CPython tutorial Appendix, for Windows a file extention of .pyw suppresses the console window that normally appears. Likewise, a console window will not be provided when using a myscript.pyw script with PyInstaller.
Also, on windows it can matter which Python distribution you're using. I used to be a fan of Anaconda, but lately I've come to prefer the python.org version because it gives me less headaches. On anaconda Python I had the problem that tkinter programs would not launch without showing a cmd window, whatever I tried. Only switching to python.org Python solved that problem.
I'm getting an interesting problem and I can't determine whether it's a problem with my code or the executable that I'm running. Basically I have a Python program that needs to call an external executable to process some data. If I call the executable via PowerShell or cmd, it works fine. However, if I attempt to run the executable via os.system() or subprocess.run(), I get the following error:
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
From my understanding of googling the issue, it would appear that this is some sort of C++-related issue, which is the language of the .exe that I'm running. I reinstalled the latest Visual C++ Redist and that did not seem to affect the problem. I've also tried to create a .bat and .ps1 script that runs the .exe. These both run fine via PowerShell and CMD, but raise the same error when run via os.system() and subprocess.run(). The error message is rather nondescript so I'm wondering if anyone knows anything about it and why os.system() etc. might be throwing it.
The relevant code is simply
os.system("GaussBin.exe gaussInput.txt gaussOutput.txt")
When the string is pasted into cmd, it runs perfectly. Additionally, if the parameters of the system() call are incorrect, the exe properly displays the usage function. It's only when I add the output.txt and the program is supposed to run fully that things start to break.
I've had some confusion about what directory os.system runs in. Should I be using .\ when calling the exe?
The .exe file is provided, not built by me.
I'm writing what should have been a very simple UAC Bypass application in python. After research and analysis, there is an identical DLL Search-order hijacking vulnerability present in Windows 7, 8, and 8.1.
First, forget all of the preparation. For example, I have, stored locally, a .cab file with a .dll inside that will launch cmd.exe. The point of this was to write it to a TEMP directory, use WUSA to extract it to the destination folder, and then execute the vulnerable application.
The reason I say forget the preparation is because it hasn't even made it into my list of problems yet. Say the destination program is "program.exe". When I double-click "program.exe," it spawns the CMD like it should. Also, when I open CMD and type "program.exe", the same things happens and I get the cmd.exe shell from the hijacked DLL.
However, onto my issue. Even when I do nothing but:
import os
os.sytem("program.exe") #Same thing with subprocess.call and Popen
I get the ORIGINAL program, NOT the hijacked one. This is very strange because it works correcty when I just double click or execute it through a normal CMD.
Is there something I'm missing? Why would this work in other scenarios but not with python?
As you can see, same security contexts... One executes with the hijacked DLL and the other launches the normal program. Why?
I have tied a python (2.7) script to a commit in mercurial. In this script, a .exe is called (via the subprocess module), which has previously been generated via the cx_freeze. This .exe basically opens a cmd prompt for receiving user inputs.
When I run a commit through the hg workbench, everything works as intended... the Python script runs, calls the executable, and does its stuff, and the commit works without a hitch.
However, when running a commit via "hg commit" in an initial cmd prompt, the executable portion of this setup never appears. I know the python script still runs. No errors are ever displayed/returned.
Am I missing something obvious, and is there a simple way to get this executable to run properly even when called from a commit in cmd prompt?
So you have mercurial calling a hook that runs a python script that launches an executable that is a python script compiled to an exe? Likely the 3-layer deep script is being run w/o a "terminal" (headless), but it sounds like if you un-snarled a few of those layers you might be better off.
I have created a little pre-commit hook in python. This hook works like a charm under Linux, but in Windows it keeps telling me:
error: cannot spawn .git/hooks/pre-commit: No such file or directory
I know there have been similar questions here about the same issue and the conclusion seams to be the shebang. My script has this on the very first line:
#!F:\PortableApps\PortablePython3.2\App\python.exe
It's also interesting to note that executing the script simply by writing .git/hooks/pre-commit works wonderful, but as soon as I try to commit, git spits out the above message.
Another interesting thing is, when I convert the encoding from ANSI to UTF-8 (using Notepad++), I get the following error when trying to execute the script:
.git/hooks/pre-commit: Cannot execute binary file
I'm using the following tools:
PortablePython 3.2.1.1
msysgit 1.7.6 (Portable)
I used the proxy-approach to make the python script work under windows (with msysgit). The complete script (with description on how I did it) might be found here: https://gist.github.com/1839424
Here is the important part about making it work under Windows
If you're working with Windows (and "msysgit"), it's a little more complicated. Since "msysgit" seems to have a problem handling the SHEBANG, you'll have to use a little trick to make the script executable (further information on this problem can be found here).
In order to make the script work, you'll want to remove the SHEBANG from the Python script ("pre-commit.py") and use a wrapper bash-script to call the interpreter. This script should look something like this:
#!/bin/sh
python .git/hooks/pre-commit.py
Store this script as a file called "pre-commit" (no file-ending). This assumes that you have Python in your PATH. If you don't, you can also specify the full path to your interpreter-executable.
This script will be called by "git commit" and call the python-script to check for the huge files. The path after the SHEBANG should not be changed, as "msysgit" will remap it automatically. You must specify a path relative to the repo-root for the Python script to be executed (because thats from where the script is called).
Afterwards you'll want to copy both the wrapper-file ("pre-commit") and the Python-script ("pre-commit.py") to your repos ".git/hooks"-directory, personalize the Python-script ("max_file_size" and "git_binary_path") and mark the "pre-commit"-file executable.