Trying to display script's output to the webui makes for messy output


bobbintb

Recommended Posts

I've got this function in my page file that runs a python script using the built-in `StartCommand.php` from the webui:
 

function scan(cmd,title,plg,func,start=0,button=0) {
  // start  = 0 : run command only when not already running (default)
  // start  = 1 : run command unconditionally
  // button = 0 : show CLOSE button (default)
  // button = 1 : hide CLOSE button
  $('#scan-button').prop('disabled', true);
  $('#scanDir').prop('disabled', true);
  $('#dbDir').prop('disabled', true);
  nchan_plugins.start();
  $.post('/webGui/include/StartCommand.php',{cmd:cmd+' nchan',start:start},function(pid) {
    if (pid==0) {
      nchan_plugins.stop();
      $('div.spinner.fixed').hide();
      $(".sweet-alert").addClass('alert');
      return;
    }
    swal({title:title,text:"<pre id='swaltext'></pre><hr>",html:true,animation:'none',showConfirmButton:button==0,confirmButtonText:"<?=_('Close')?>"},function(close){
      nchan_plugins.stop();
      $('div.spinner.fixed').hide();
      $('.sweet-alert').hide('fast');
      setTimeout(function(){bannerAlert("<?=_('Attention - scanning continues in background')?> ["+pid.toString().padStart(8,'0')+"]<i class='fa fa-bomb fa-fw abortOps' title=\"<?=_('Abort background process')?>\" onclick='abortScan("+pid+")'></i>",cmd,plg,func,start);});
    });
    $('button.confirm').prop('disabled',button!=0);
  });
}


When I run the python script in the terminal during development, everything looks great.
https://github.com/bobbintb/UnRAID-DeDuper/blob/release/src/scripts/main.py
But when I test it in UnRAID in the webui, there are all kinds of character encoding issues. I don't really know how to deal with that in the webui side of things as I'm still kind of new at web development. Instead of the neatly displayed progress bars (2), I get something like this:
 

0%|�[34m �[0m| (30.4G
0%|�[34m �[0m| 0.00/11.9G�[
1%|�[34m▍ �[0m| 122M/11.9G�[A 0%|�[34m▏ �[0m|, 0/116 (30.4G
2%|�[34m▉ �[0m| 244M/11.9G�[A 1%|�[34m▍ �[0m|, 0/116 (30.4G
3%|�[34m█▍ �[0m| 366M/11.9G�[A 1%|�[34m▋ �[0m|, 0/116 (30.4G
4%|�[34m█▉ �[0m| 488M/11.9G�[A 2%|�[34m▊ �[0m|, 0/116 (30.4G
5%|�[34m██▍ �[0m| 609M/11.9G�[A 2%|�[34m█ �[0m|, 0/116 (30.4G
6%|�[34m██▉ �[0m| 731M/11.9G�[A 3%|�[34m█▎ �[0m|, 0/116 (30.4G
7%|�[34m███▍ �[0m| 853M/11.9G�[A 3%|�[34m█▍ �[0m|, 0/116 (30.4G
8%|�[34m███▉ �[0m| 975M/11.9G�[A 3%|�[34m█▋ �[0m|, 0/116 (30.4G
9%|�[34m████▍ �[0m| 1.07G/11.9G�[A 4%|�[34m█▉ �[0m|, 0/116 (30.4G
10%|�[34m████▉ �[0m| 1.19G/11.9G�[A 4%|�[34m██ �[0m|, 0/116 (30.4G
11%|�[34m█████▍ �[0m| 1.31G/11.9G�[A 5%|�[34m██▎ �[0m|, 0/116 (30.4G
12%|�[34m█████▉ �[0m| 1.43G/11.9G�[A 5%|�[34m██▌ �[0m|, 0/116 (30.4G
13%|�[34m██████▍ �[0m| 1.55G/11.9G�[A 5%|�[34m██▋ �[0m|, 0/116 (30.4G
14%|�[34m██████▉ �[0m| 1.67G/11.9G�[A 6%|�[34m██▉ �[0m|, 0/116 (30.4G
15%|�[34m███████▍ �[0m| 1.79G/11.9G�[A 6%|�[34m███▏ �[0m|, 0/116 (30.4G
16%|�[34m███████▉ �[0m| 1.90G/11.9G�[A 7%|�[34m███▎ �[0m|, 0/116 (30.4G
17%|�[34m████████▍ �[0m| 2.02G/11.9G�[A 7%|�[34m███▌ �[0m|, 0/116 (30.4G
18%|�[34m████████▉ �[0m| 2.14G/11.9G�[A 8%|�[34m███▊ �[0m|, 0/116 (30.4G
19%|�[34m█████████▍ �[0m| 2.26G/11.9G�[A 8%|�[34m███▉ �[0m|, 0/116 (30.4G
20%|�[34m█████████▉ �[0m| 2.38G/11.9G�[A 8%|�[34m████▏ �[0m|, 0/116 (30.4G
21%|�[34m██████████▍ �[0m| 2.50G/11.9G�[A 9%|�[34m████▍ �[0m|, 0/116 (30.4G
22%|�[34m██████████▉ �[0m| 2.62G/11.9G�[A 9%|�[34m████▋ �[0m|, 0/116 (30.4G
23%|�[34m███████████▍ �[0m| 2.74G/11.9G�[A 10%|�[34m████▊ �[0m|, 0/116 (30.4G
24%|�[34m███████████▉ �[0m| 2.86G/11.9G�[A 10%|�[34m█████ �[0m|, 0/116 (30.4G
25%|�[34m████████████▍ �[0m| 2.98G/11.9G�[A 11%|�[34m█████▎ �[0m|, 0/116 (30.4G
26%|�[34m████████████▉ �[0m| 3.09G/11.9G�[A 11%|�[34m█████▍ �[0m|, 0/116 (30.4G


It looks like this normally:
 


  5%|██▌                                               |, 0/116 (30.4G)
 12%|█████▉                                            | 1.43G/11.9G


I'm sure it has to do with the ANSI characters or something and I know it's probably just a simple thing for someone who knows what they are doing to just specify the correct encoding. Even after spending a few hours on it, I just don't know where to begin looking. Any Ideas?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.