subprocess problem
The Problem with the subprocess code is: Using the sourcecode functioning as normal. The frozen app with cx_freeze on every platform just returns an empty result Here is the code in short: def get_path_pandoc(): settings = QSettings('Pandoc', 'PanConvert') path_pandoc = settings.value('path_pandoc','') if not os.path.isfile(path_pandoc): if platform.system() == 'Darwin' or os.name == 'posix': args = ['which', 'pandoc'] p = subprocess.Popen( args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) path_pandoc = str.rstrip(p.communicate(path_pandoc.encode('utf-8'))[0].decode('utf-8')) The whole problematic code can be checked on http://github.com/apaeffgen/panconvert in source/converters/interface_pandoc.py I debugged it with some QMessage-Boxes. I just know, that the returnd result is empty. I tried some stderr on this code also. But also the error message is empty. Any hints what could be changed in the code, so it also works in the frozen app? At the moment i use python3.4 to 3.5 depending on the platform (Mac, Win, Linux) P.S. Tried also some code with invoking the bash and afterwords the which pandoc code. To know avail also -- https://mail.python.org/mailman/listinfo/python-list
Re: subprocess problem
Maybe i could use another trick to circumvent the problems in the frozen app? The frozen apps can be downloaded here: https://sourceforge.net/projects/panconvert/files/Newest/ @Cameron: 1. I use PyQT5 for a creating a gui app. To run the app on other systems, where no QT5 and PyQT5 is installed, a bundle is created with all relevant libraries, so it will start independently. This app bundle, is called a frozen app. Not only the source code, but all it dependencies are distributed including python3 itself. 2. In the test-environment pandoc is installed in /usr/local/bin/pandoc (Mac) or /bin/pandoc (Linux). Which returns the path correctly, at the terminal (shell), in Python and in the Gui-App Panconvert. 3. I am aware of the limitations of which. There is a fallback to manually insert the path. So the app will function anyway. And i want to avoid to search the whole filesystem. This takes minutes on my test machines, so this is no option. 4. I suppose that something is different from executing the code in the frozen state. The app e.g. on Mac is not started from a python shell or a comand shell. But even on linux, when started from a shell it does not work. 5. I will try the hint with dev.null and the p.check_returncode() @Wolfgang 1. The function should be executed only, if the path is unknown. If the user enters the path manually in the settings and pandoc exists, the function should not be executed to save computation time. 2. Only if the manually entered path is not correct or empty the function should be executed, hence 'if not os.path.isfile(path_pandoc)' 3. The function fills in the path automatically if which returns a value. This works in the source code -- https://mail.python.org/mailman/listinfo/python-list
Re: subprocess problem
I guess which does not return an error code. If it does not find anything, the return is just blank. If it finds something, the path is returned. So the change of code did not help, because there is just no error message. Could there be a $path problem in the subprocess started inside the binary? -- https://mail.python.org/mailman/listinfo/python-list
Re: subprocess problem
Thanks for all the great advice. I tested all the possibilities. So far no luck. If i start the app from a terminal, the solutions work. But not, if i start the app-bundle (There is no connection to a terminal) 1. Copied the path to p.subprocess 2. Used the def wich: python function 3. Used shutil When there is no Terminal, there is no error message / status code message. -- https://mail.python.org/mailman/listinfo/python-list
Re: subprocess problem
On 2017-02-11 02:23:12 +, Cameron Simpson said: def your_function(...): with open('/path/to/your/logfile.txt', 'a') as logfp: print("PATH=".os.environ['PATH'], file=logfp) p=Popen(...) p.communicate(...) print("p.returncode=%r" % (p.returncode)) and any other interesting values that occur to you. This is really simple, and doesn't require a terminal or using the logging module. You can 'tail -f /path/to/your/logfile.txt' in another terminal to watch stuff happen as you exercise the program. Thanks for the great advice. I found out, that the frozen app does not pass the normal path variable. All the tricks with passing the correct environment did not work. I just hardcoded the existing standard path. After that it worked. I think it is a problem with frozen apps in general. Cx_Freeze has other problems than Pyinstaller. But all need some workarounds for the problems. -- https://mail.python.org/mailman/listinfo/python-list