Inside a Flask app I try to run Python subprocess
module. All worked on Ubuntu 12.04 with Python 2.7.8 and now I'm trying to check if the app works on Windows as well (Win7 x64, Python 2.7.12). My piece of code that works on Linux:
try:
command = ["pgsql2shp -f %s -h %s -u %s -P %s %s main.%s" % (path, host, user, pword, db_name, region)]
work = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Above doesn't on Windows, returning stderr
like "The filename directory name or volume syntax is incorrect".
But:
try:
work = subprocess.Popen("pgsql2shp -f %s -h %s -u %s -P %s %s main.%s" % (path, host, user, pword, db_name, region), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Above works on Windows! What is the reason here? The error brought me to thinking that my path
variable is incorrect, but it is as below:
path = 'D:/adam/files/test.shp'
print path # D:/adam/files/test.shp
path = os.normpath(path)
print path # D:\adam\files\test.shp
path # 'D:\\adam\\files\\test.shp'
If I run postgres' pgsql2shp
from Windows cmd and just paste whatever combination of \
, \\
or /
in string and the data I use here, it works good. Looks like pgsql2sgp
converts the path to needed format itself. Then why it won't work through Python script and separate command
variable?