0

I am trying to populate a dropdownlist with the result of the execution of an .exe program. The .exe will return a concatenation of items, separated by special characters. This will in turn be captured by the corresponding view at views.py, and rendered to the .html. In this .html, there is javascript code that runs on window load, splits the rendered string using the special characters and (theorically) populates the dropdownlist.

Part of my code is as follows:

the c++ code (will be compiled into the .exe)

   while(i<MAX_ITEMS)    
        std::cout << i << "$" << item[i] << "&";

views.py (inside of the view that the url is calling)

os.chdir(r'C:/directory')
proc = subprocess.Popen([r'C:/directory/Application.exe'], stdout=subprocess.PIPE)
y = proc.stdout.read()
proc.wait()
return render_to_response('home.html', {'list': y})

finally, the html file containing the javascript function

<html> 
    <head> 
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 
        <title></title> 
        <script type="text/javascript" charset="utf-8"> 
            window.onload = function Func() {               
                var lists = document.getElementById('list'); 
                var liststxt = new Array();
                liststxt[1] = "{{ list }}";
                var items = liststxt[1].split("&"); 
                for (var count = lists.options.length-1; count >-1; count--){ 
                    lists.options[count] = null; 
                } 
                for (i=0; items.length; i++){ 
                    var values = items[i].split("$"); 
                    var option = new Option(values[1], values[2], false, false);  
                    lists.options[lists.length] = option; 
                }                          
            } 
        </script> 
    </head> 
    <body>  
        <form action="" method="get" accept-charset="utf-8"> 
            <select name="list" id="list"> 
                <option>--</option> 
            </select>                 
        </form> 
    </body> 
</html>

I think I have tried almost all intermediate possibilities, and they work perfect (hardcoding a string instate of reciveing it from the exe, rendering the result of the .exe directly at the html instate of processing it using javascript, etc.), but if I put everything together, it fails to populate the dropdownlist...

I am doing this code in order to have several dependant dropdownlists, and I am doing it following the proof of concept seen here. I am not using Ajax (or Dajax, or Dajaxice), because I couldn't manage to install it properly after trying many times.

Thanks a lot!

9
  • You don't need to "install" Ajax: it's a technique, not a library. But can you provide an example of the output of your exe file? Commented Jul 17, 2013 at 11:09
  • The exe outputs something like that: 1$First Item&2$Second Item&3$Third Item... This information is recived at the views, as I can display it in the screen using HttpResponse. It is also reaching the html, as I can render it to the html and display it. But I fail using it at the javascript function. On the other hand, if I pass to the javascript function the same string I would get from the exe, but now I hardcode it at views.py, it works Commented Jul 17, 2013 at 11:23
  • Are you sure it is exactly the same? Is there any extra stuff before or after the value? What do you get if you put a print statement in the view, eg print "Output: " + y + "..."? Commented Jul 17, 2013 at 11:55
  • yes, I can't see any difference... Commented Jul 18, 2013 at 9:24
  • if I take what I get at "y" using print, I copy it and manually hard-code it at views, then the javascript works fine Commented Jul 18, 2013 at 10:03

0

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.