I have been having some problems with subprocess.call()
, subprocess.run()
, subprocess.Popen()
, os.system()
, (and other functions to run command prompt commands) as I can't seem to get the msg
command to work.
import subprocess
subprocess.call("msg * Hey",shell=True)
In theory, this should send "Hey" to every computer on the network unfortunately, this isn't running at all and I'm not quite sure why. I can run it on cmd
successfully, but can't get it to work from Python.
I'd love to hear why this doesn't work and hopeful a way to fix my code or an alternate solution.
Edit: Solved, thanks for everyone's help. Upgrading to 64-bit Python did the trick.
In 64-bit Windows, "msg.exe" is only distributed as a native 64-bit binary. This file won't be found if you're using 32-bit Python, which executes under WOW64 emulation. WOW64 redirects "System32" access to the "SysWOW64" directory. In Windows 7+, use the virtual "SysNative" directory to access the real "System32". For example:
sysroot = os.environ['SystemRoot']
sysnative = os.path.join(sysroot, 'SysNative')
if not os.path.exists(sysnative):
sysnative = os.path.join(sysroot, 'System32')
msgexe_path = os.path.join(sysnative, 'msg.exe')
subprocess.call([msgexe_path, '*', 'Hey'])
Note that msg.exe has nothing to do with CMD, so there's no reason to use shell=True
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With