Menu

Capture output "written XX% done"

Wierd Jan
2013-11-11
2013-11-18
  • Wierd Jan

    Wierd Jan - 2013-11-11

    Hello,

    I created a script to restore images. Now I would like to create a gauge (dialog) to show the progress. I can do "imagex --verbose", but that wil only show the files. I cant seem to capture the "%" during the process, only after is has been 100% written. Is there a way to "grep" the percentage when the imagex is in the process of writing the image.

    Thank you

     

    Last edit: Wierd Jan 2013-11-11
  • synchronicity

    synchronicity - 2013-11-11

    Hi,

    The problem is that wimlib-imagex outputs a carriage return rather than a newline when it prints the informational lines containing the percentages you're interested in. This is intentional so that the output stays on the same line when used interactively, but if you pipe that output to 'grep' it won't distinguish between lines. You could work around this by piping the output to a command that translates carriage returns to newlines, for example:

    wimapply test.wim dir | stdbuf -o L tr '\r' '\n'  | grep '%'
    

    That uses the tr program to do the translation. stdbuf (part of GNU coreutils) is needed to set the tr output to line-buffered.

    Do note that you could instead write your own C or C++ program that uses wimlib directly. In that case, you could supply your own progress function to be called during the extraction.

     
  • Wierd Jan

    Wierd Jan - 2013-11-18

    Thank you!!!. It would take a lot longer to figure this out myself. I works!!! My script is now working with a progress bar!. Thank you.

    WJ

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.