Forum

Author Topic: Write internal Agisoft stdout to log, along with own messages, with batch script  (Read 5196 times)

Braden99

  • Newbie
  • *
  • Posts: 4
    • View Profile
 Hey

I'm a bit stuck at the moment, I'm trying to route Agisofts own stdout to a log. A bit of background first....

I've got a XML batch script which gets invoked on Deadline. Metashape gets called with the -platform offscreen argument, the xml with -xml argument, and the Python file called batch_runner.py with the -r argument.

The batch _runner.py gets invoked for each xml of our pipeline. Each xml contains details for running multiple Python nodes like (ImportPhotos.py or Align.py).
The batch_runner.py currently parses the XML to find script paths and args, and then calls run_script method for each, to run the proper Python module.

In the batch_runner.py file at the bottom in __init__, I switch the stdout to my own object, that can write out to a log.
if __init__ == "__main__":
    # .... other code lines
    # Keep the old stdout
    sys._stdout = sys.stdout
   # Route stdout to my own log file
    sys.stdout = logger_write_continually.LoggerWriteContinually(log_file_path)
   # Run all the tasks of XML batch file using custom Python object
   AgisoftBatchRunner(args)
   # Restore original stdout
    sys.stdout = sys._stdout

The problem is this only captures messages that I "print" within the called Python modules (like Align.py).
It doesn't include the exhaustive Metashape messages, about what's happening under the hood.

Is there anyway to route all stdout, my own and Agisofts to a log file?

Thanks
Braden
« Last Edit: January 25, 2021, 10:27:42 PM by Braden99 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15282
    • View Profile
Hello Braden,

Have you tried just to redirect the output to file in the following way that will save to the single file both stderr and stdout (you can use print statements in the script to print anything to stdout):
Code: [Select]
metashape.exe -r script.py > D:/out.log 2>&1
Best regards,
Alexey Pasumansky,
Agisoft LLC

Braden99

  • Newbie
  • *
  • Posts: 4
    • View Profile
Hey Alex

That's a great idea...

Although from my understanding the console redirect will require the process to complete first?

Some of our Agisoft processes take many hours, and I want to show all the log details immediately, in my external Qt widget / app.

Also I tried the suggestion and my log was empty even after the process completed.

Any more ideas?

Thank you

Braden99

  • Newbie
  • *
  • Posts: 4
    • View Profile
« Last Edit: January 26, 2021, 04:12:35 AM by Braden99 »

Braden99

  • Newbie
  • *
  • Posts: 4
    • View Profile
Hey

I found out this was an issue with the Deadline CommandLine plugin. and have now found a work around so the log is written

Thanks again Alexey
« Last Edit: January 26, 2021, 04:12:13 AM by Braden99 »