Okay so my best guess currently is that I've severely screwed up my python environment somehow and I have no idea how.
First off, I have tried uninstalling and reinstalling (actually upgrading from 2.7.14 to .15) python to no avail. the problem persists.
The problem description as best as I understand it:
I am trying to call a Windows native binary from Python 2.7.15 (displayswitch.exe, which is verified existing in C:\Windows\System32\). Note: I didn't miss the double slashes, stack overflow is taking away the trailing ones for some reason. Probably an escape sequence.
At one point this was working just fine, which leads me to believe I screwed something up. As of this moment, I am able to call displayswitch, and any other native command just fine from a windows command prompt, but running the exact same command from os.system, subprocess.call gives me the errors "displayswitch is not recognized as an internal or external command" and "WindowsError: The system cannot find the file specified", respectively.
Here are snippets of exactly what I'm running, copied from the command line for sanity reasons:
(dos)
displayswitch.exe --> runs fine
(python interpreter)
import os
os.system("displayswitch.exe")
--> 'displayswitch' is not recognized as an internal or external command,
operable program or batch file.
1
(python interpreter)
import subprocess
subprocess.call(["displayswitch.exe"])
--> WindowsError: [Error 2] The system cannot find the file specified
My first instinct was that I had screwed up my path variable (which again is a long shot because I haven't touched it with a 30 foot pole), but if i print out os.environ["PATH"], the path to C:\Windows\System32 is in there (i split it on semicolons so it'd be easier to see):
C:\\Python27\\;
C:\\Python27\\Scripts;
C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;
C:\\Program Files (x86)\\Razer Chroma SDK\\bin;
C:\\Program Files\\Razer Chroma SDK\\bin;
C:\\Windows\\system32;
C:\\Windows;
C:\\Windows\\System32\\Wbem;
C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;
C:\\Program Files\\PuTTY\\;
C:\\WINDOWS\\system32;
C:\\WINDOWS;
C:\\WINDOWS\\System32\\Wbem;
C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;
C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;
C:\\Program Files\\TortoiseSVN\\bin;
C:\\Users\\iwasf\\AppData\\Local\\Microsoft\\WindowsApps;
C:\\sqlite;
C:\\Program Files (x86)\\WinMerge;
C:\\WINDOWS\\system32;
C:\\WINDOWS;
C:\\WINDOWS\\System32\\Wbem;
C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;
C:\\WINDOWS\\System32\\OpenSSH\\;
C:\\Program Files\\Git\\cmd;
C:\\Program Files\\Git\\mingw64\\bin;
C:\\Program Files\\Git\\usr\\bin;
C:\\Users\\iwasf\\PycharmProjects\\PyBedTime\\lib\\ffmpeg\\bin;
C:\\GLUT;
C:\\GLUT\\include;
C:\\Users\\iwasf\\AppData\\Local\\Microsoft\\WindowsApps;
But hey, In the essence of eliminating the middleman I went ahead and tried calling the full path to executable (i.e C:\Windows\System32\displayswitch.exe) with the same exact results (I also tried case sensitive i.e DisplaySwitch.exe in case that mattered, it didn't).
I have never had a problem like this in 3 years and i'm really at a loss with what to even try. I even tried rebooting my pc which worked just as much as expected.
Other information about my environment and what may have caused this for some reason: Using PyCharm 2018.2.2 IDE, which creates and uses virtualenv for projects.
For the side project I've been working on when this problem first arose, I was originally using python 3.6.6 with flask, pigpio and pyaudio (running this on a raspberry pi) but switched everything over to python 2.7 when I hit a roadblock with mod_wsgi and installing it for python 3.6 which wasn't having any of it.
In PyCharm i've configured it to use both a local interpreter and a remote interpreter, all of which worked flawlessly. The issue with os.system occurred sometime after I made the switch from 3.6 back to 2.7 but I can't directly vouch for that being the exact root cause or not. I made a new virtualenv using 2.7 and deleted the old one using 3.6 from my project.
I've done some intermediate level googling on this issue but 90% of the results were people having the command typed wrong or they were instructed to use subprocess to avoid issues with parameter passing, etc. But as i've tried both and the same command works from command prompt I've convinced myself that it can't be my typing skills.
EDIT: Just had the thought to try it with python 3.6 again, which works fine and i'm even more baffled. If it were a problem specific to 2.7 I would have thought reinstalling would have fixed it.