我在使用subprocess.call
和os.path.expanduser
时遇到了一些问题。
我需要在非自己的计算机上运行此脚本,我遇到的一个问题是在用户名包含空格C:\User\User Example
的PC上运行脚本。我在之前的帖子中被告知我应该使用带有列表的args。但是,我不明白这意味着什么。任何教程或相关的帖子将不胜感激。
# Set varible for gdal_calc
gdal_calc = "C:\\Program Files (x86)\\GDAL\\gdal_calc.py"
# make dictionary of environmental variables
gdal_env = os.environ.copy()
# modify and add variables
gdal_env["GDAL_DATA"] = "C:\\Program Files (x86)\\GDAL\gdal-data"
gdal_env["GDAL_DRIVER_PATH"] = "C:\\Program Files (x86)\\GDAL\\gdalplugins"
gdal_env["PATH"] = gdal_env["PATH"] + ";C:\\Program Files (x86)\\GDAL"
# Set constants
# The pathway to the images files are nested within the '--outfile=' command
inHVZero = os.path.expanduser('~\\Desktop\\Components\\Zeros\\newHVZeros_.img')
outPlace = os.path.expanduser('~\\\Desktop\\Components\\db_Files\\newHVdB.img')
outVFile = '--outfile='+ outPlace
cmd_HV = ['-A', inHVZero, outVFile, '--calc=10*log10(power(A,2))-83']
#calc_cmd_HV = ['C:\\Program Files (x86)\\GDAL\\gdal_calc.py', '-A', inHVZero, '--outfile='+outPlace, '--calc=10*log10(power(A,2))-83']
inVHZero = os.path.expanduser('~\\Desktop\\Components\\Zeros\\newVHZeros_.img')
outPlace_1 = os.path.expanduser('~\\Desktop\\Components\\db_Files\\newVHdB.img')
outVFile_1 = '--outfile='+ outPlace_1
cmd_VH = ['-A', inVHZero, outVFile_1, '--calc=10*log10(power(A,2))-83']
#calc_cmd_VH = ['C:\\Program Files (x86)\\GDAL\\gdal_calc.py', '-A', inVHZero, '--outfile='+outPlace_1, '--calc=10*log10(power(A,2))-83']
subprocess.call([sys.executable,gdal_calc] + cmd_HV, env=gdal_env)
subprocess.call([sys.executable,gdal_calc] + cmd_VH, env=gdal_env)