I primary work on GNU/Linux but sometimes have to deal with Windows.
I found out that subprocess
isn't able to see the home folder on Windows when shell=False
(default).
#!/usr/bin/env python3
from pathlib import Path
import subprocess
homepath = Path.home()
try:
subprocess.Popen(['dir', homepath]) # WinError 2
except FileNotFoundError:
print('Can not find')
subprocess.Popen(['dir', homepath], shell=True) # OK
I wonder why it is that way. Because on GNU/Linux there is no such a restriction and I'm able to run subprocess activies with HOME
involved with shell=True
.
But using shell=True