I have a question about a simple script. The goal of the script is to find all tgz files in a subdirectory and extract all the TIF files from them that have B4 or B5 at the end of the file name. After that it shoyld move those files to a specified subdirectory (band4 or band5, respectively).
It seems to be working fine on my Ubuntu 12.04 machine, but when a buddy of mine executes it on his Windows 7 machine it breaks. From what I understand, the script calls on linux commands and Windows cant interpret them correct (cant find *.tgz files). I was wondering if there is way to make it OS agnostic achieving the same results.
import subprocess, shlex, os, sys
cmd1 = "find . -name *.tgz"
cmd2 = "xargs -i pigz -dv {}"
args1 = shlex.split(cmd1)
args2 = shlex.split(cmd2)
p1 = subprocess.Popen(args1, stdout=subprocess.PIPE)
p2 = subprocess.Popen(args2, stdin=p1.stdout, stdout=subprocess.PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
output = p2.communicate()[0]
cmd1 = "find . -name *.tar"
cmd2 = "xargs -i tar -xfv {} --wildcards '*B5.TIF' '*B6.TIF' '*B8.TIF' -C %s" % repo
args1 = shlex.split(cmd1)
args2 = shlex.split(cmd2)
p1 = subprocess.Popen(args1, stdout=subprocess.PIPE)
p2 = subprocess.Popen(args2, stdin=p1.stdout, stdout=subprocess.PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
output = p2.communicate()[0]
pathname = os.path.dirname(sys.argv[0])
b4 = os.path.abspath(pathname)+'/Band_4'
b5 = os.path.abspath(pathname)+'/Band_5'
os.mkdir(b4)
os.mkdir(b5)
cmd1 = "find . -name *B4.TIF"
cmd2 = "xargs -i mv -if {} Band_4"
args1 = shlex.split(cmd1)
args2 = shlex.split(cmd2)
p1 = subprocess.Popen(args1, stdout=subprocess.PIPE)
p2 = subprocess.Popen(args2, stdin=p1.stdout, stdout=subprocess.PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
output = p2.communicate()[0]
cmd1 = "find . -name *B5.TIF"
cmd2 = "xargs -i mv -if {} Band_5"
args1 = shlex.split(cmd1)
args2 = shlex.split(cmd2)
p1 = subprocess.Popen(args1, stdout=subprocess.PIPE)
p2 = subprocess.Popen(args2, stdin=p1.stdout, stdout=subprocess.PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
output = p2.communicate()[0]
Error Traceback:
Traceback (most recent call last):
File "[PATH]\bands.py", line 36, in <module>
p2 = subprocess.Popen(args2, stdin=p1.stdout, stdout=subprocess.PIPE)
File "C:\Python27\ArcGIS10.2\lib\subprocess.py", line 711, in _init_
errread, errwrite)
File "C:\Python27\ArcGIS10.2\lib\subprocess.py", line 948, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
File not found - *.tgz