c# - Output from py2exe converted program gets received all at once -


i have made python console script, , converted .exe py2exe (i have used console = ['test.py'] line in setup file).

the program parses file, , during parse prints out how of file has parsed. typical output be:

processing (currently @ 1%) processing (currently @ 4%) 

etc. when running file in cmd window works expected.

i have created small c# wpf program runs parser:

process p = new process(); p.startinfo = new processstartinfo(@"c:\temp\test.exe"); p.startinfo.redirectstandardoutput = true; p.startinfo.useshellexecute = false; p.startinfo.createnowindow = true;  p.outputdatareceived += new datareceivedeventhandler(p_outputdatareceived);  task t = new task(() => {     p.start();     p.beginoutputreadline();     p.waitforexit();     p.close(); }); t.start(); 

the p_outputdatareceived handler sends received output textbox. works , have tested on other programs, , there output program when expect.

however when run parser (the 1 created py2exe) outputs after parser has finished. in end correct output, them @ same time...

(note, don't 1 big output, rather expected outputs still, @ same time)


so clear here:

  • if run parser command window, outputs 1 one
  • i have tested run c# console program instead of py2exe generated program , works (i outputs 1 one)

python checks if sys.stdout (the program's standard output) console. if is, python flushes write buffers user can see it. otherwise writes cached , outputted @ once:

  • when write buffer full or
  • at program exit.

the logic behind better performance, since when redirecting stdout file or other programs, typically no 1 cares when output occurs.

you can fix this including sys.stdout.flush() in strategic locations in python parser script (i.e. directly after printing status line).

btw: should able observe same time-delay behavior if redirect output of parser more, example:

c:\temp\test.exe | more 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -