Making "print" print...

Hello,

a true rooky-question:

how do I make the "print" command print immediately?

Problem: I have a long running script and want to "print" status information. But all print messages only are printed (all together) when the batch job finishes.

So I guess it has something to do with the print buffer that is not emptied, or some higher-priority processing...

Thanks!

p.
SystemAdmin - Tue Jun 28 11:55:11 EDT 2011

Re: Making "print" print...
Mathias Mamsch - Tue Jun 28 14:32:08 EDT 2011

This is not a DOORS specific issue. The output of console scripts is buffered by default. To circumvent buffering you can use cout instead of print and do a 'flush cout' which will empty the output buffer. If you have scripts with a lot of print that you don't want to change you can just override print at the beginning of your batch script:
 

void print (string s) { cout << s; flush cout }

 


This should resolve the issue. Hope this helps. Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Making "print" print...
llandale - Tue Jun 28 16:02:58 EDT 2011

Mathias Mamsch - Tue Jun 28 14:32:08 EDT 2011

This is not a DOORS specific issue. The output of console scripts is buffered by default. To circumvent buffering you can use cout instead of print and do a 'flush cout' which will empty the output buffer. If you have scripts with a lot of print that you don't want to change you can just override print at the beginning of your batch script:
 

void print (string s) { cout << s; flush cout }

 


This should resolve the issue. Hope this helps. Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Is there an equivalent technique for interactive scripts?

Re: Making "print" print...
Mathias Mamsch - Tue Jun 28 17:08:48 EDT 2011

llandale - Tue Jun 28 16:02:58 EDT 2011
Is there an equivalent technique for interactive scripts?

I think interactive scripts do not suffer from the same problem, as they don't output to a buffered console. However you can always use the same technique to redirect the prints of a program, for example to a file or to filter them, or whatever. Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Making "print" print...
llandale - Tue Jun 28 18:01:04 EDT 2011

Mathias Mamsch - Tue Jun 28 17:08:48 EDT 2011
I think interactive scripts do not suffer from the same problem, as they don't output to a buffered console. However you can always use the same technique to redirect the prints of a program, for example to a file or to filter them, or whatever. Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Your code does not work for me interactively:

void print (string s) { cout << s; flush cout; infoBox("print") }
print "hello"

Run from the DXL window I get the info box but nothing printed.

I suspect an issue with the way this company sets things up, as I cannot get win32SystemWait_ to work here either.

  • Louie

Re: Making "print" print...
Mathias Mamsch - Wed Jun 29 04:49:47 EDT 2011

llandale - Tue Jun 28 18:01:04 EDT 2011
Your code does not work for me interactively:

void print (string s) { cout << s; flush cout; infoBox("print") }
print "hello"

Run from the DXL window I get the info box but nothing printed.

I suspect an issue with the way this company sets things up, as I cannot get win32SystemWait_ to work here either.

  • Louie

You are right, I did not realize cout does not seem to work in interactive window ... Do I guess one would need to do an:
 

void printOld (string s) { print s }
 
void print (string s) {
  if (isBatch()) { 
     cout << s; flush cout
  } else {
     printOld s
  }
}
 
print "Hello"

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS