1

In my Python/Django code I call gdalbuildvrt process. This process should create a .VRT file, but it does not. In order to check it, I write the subprocess output to a debug file. This is how I do it:

process = subprocess.Popen(["gdalbuildvrt", mosaic, folder], stdout=subprocess.PIPE)
stdout = process.communicate()[0]

with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "debug.txt"), 'w') as file:
    file.write('{}'.format(stdout) + " -> " + mosaic)

As a result I see this in debug.txt file:

b'0...10...20...30...40...50...60...70...80...90...100 - done.\n' -> /var/www/vwrapper/accent/accent/layers/raw/mosaic.vrt

So, as you can see the first part of debug statement says, that it'ok:

0...10...20...30...40...50...60...70...80...90...100 - done.

And the second part says, that /var/www/vwrapper/accent/accent/layers/raw/mosaic.vrt should be created. However, when I go to the target folder and refresh it, I see no mosaic.vrt file there. So, what may be wrong with that and how can I fix it? I should add that on Windows machine it's 100% ok, but on CentOS it does not.

2
  • Log stderr and the .returncode... that's where any problems will be. Commented Mar 24, 2017 at 20:18
  • @TemporalWolf. Would you be so kind to elaborate on this a little bit? You may make a complete answer, if you wish. Commented Mar 24, 2017 at 20:20

1 Answer 1

4
process = subprocess.Popen(["gdalbuildvrt", mosaic, folder], 
                           stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
ret = process.returncode

or

process = subprocess.Popen(["gdalbuildvrt", mosaic, folder], 
                           stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

which will redirect stderr to stdout.

Then log those two things:

All error logging should be on stderr, not stdout. And any return code will appear via process.returncode.

You could also probably use one of the higher processes, like subprocess.check_call()

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! I've just checked it. stderr gets None value and ret gets 0 value. It seems like there are no errors, but still process does not do, what it should do. I really wonder, what may be wrong.
@Jacobian I made an edit. you have to make sure you add a pipe for stderr or redirect it to stdout
Fantastic! Now I see where the error was. Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.