3

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.

  • 3
    Is the `.exe` a program you wrote an built yourself? You should also edit your question to at least include the code where you run the program with `os.system`. – MrPromethee Nov 21 '19 at 08:51
  • 3
    The exe is failing in controlled a manner for [some reason](https://stackoverflow.com/q/8177152/503046). – vonPryz Nov 21 '19 at 09:00
  • 2
    You should be seeing a different error message if Python were unable to find the executable. – Ansgar Wiechers Nov 21 '19 at 09:26
  • Does this mean that it's a problem with the cpp executable itself? I don't understand how it's failing when called via python but not when called via a batch file/powershell script/directly through command line – PWallington Nov 21 '19 at 09:30
  • GaussBin.exe still runs fine via the cmd loaded from that directory. Comspec is the system32 cmd but that also runs the command fine on its own. I expect the directory running GaussBin via the program to just be the directory the program is run from, and assumed that's how it would work. – PWallington Nov 21 '19 at 11:44
  • I'm getting an exit code of 3 from the program, according to the %errorlevel% echo. Looking at the source code of gaussBin, there's nowhere specifically that would return 3, so I'm not quite sure how this is happening. – PWallington Nov 21 '19 at 11:49
  • 1
    @PWallington The error message means that the `abort()` function is called, which ends the program with an exit code of 3. – MrPromethee Nov 21 '19 at 13:15
  • I read that, but I still fail to see how a program could be acting differently when called programatically as opposed to being called manually as long as the inputs are the exact same @MrPromethee – PWallington Nov 21 '19 at 13:23

0 Answers0