How to timeout in DOORS DXL? - ibm-doors

The want the execution to stop for example 5 seconds and then resume execution. the code below seems to be fine but it's not working. It executes directl, it doesn't wait. Can please someone help?
sleep_(50)
string out=""
print win32SystemWait_("cmd.exe /C echo hallo", out, -1)
print "Output :" out

Okay I found an answer my code is correct.
The thing is void sleep_(int milliseconds)

Related

How to make Postman/Newman to fail a test after certain time has passed?

So, in my collection I have about ten requests, with the last two being:
/Wait 10 seconds
/Check Complete
The first makes a call to the postman's echo (delay by 10 seconds) and the second is the call to my system to check for the status complete. Now, if status is unavailable I wait another 10s:
postman.setNextRequest("Wait 10 seconds");
The complete status on my system can appear in a minute or so. Now, as one can see - it is an infinite loop if something goes wrong with the system and status is never complete. Is there a way in postman/newman test to fail a test if it has been going for more than 2 minutes, for example.
Additionally, this will be executed in jenkins with command line, so I am not really looking into postman settings or delays between requests in the runner.
you may have a look to newman options here : https://www.npmjs.com/package/newman#newman-run-collection-file-source-options. The interesting option is
--timeout-request : it will surely fulfill your need.
In Postman itself, you may test the responseTime. I recall that there is a snippet, on the right part, which looks like this:
tests["Response time is less than 200ms"] = responseTime < 200;
and which could help you as the test fails if response does not occur within the requested time.
Alexandre
If you are going to be using Jenkins pipeline you can use the timeout step to cause long running jobs to result in failure, here's on for 2 mins.
timeout(120) {
node {
sh 'newman command'
}
}
Check out the "Pipeline Syntax" editor in Jenkins to generated your code block and look for other useful functions.

VISUAL DATAFLEX How can I get the exit code of Runprogram

Im launching a DOS program using Runprogram wait "command plus args" wich exits with 1 whenever an error happends and 0 when everything works as expected...
Problem is, I'm unable to catch that exit code.
I have tryed using ShellExecuteA but dataflex wont wait for it to close...
I have also tryed to use Chain Wait without any possitive result.
I'm using VDF 18.2 my App is a desktop app.
I finally found the answer which is working like a charm. Seems to be that DataFlex has this "magic variable" called strmark which is cleaned and filled everytime I issue the command Runprogram Wait ('program') ('args').
So at the end of the day we can do something like this:
Runprogram Wait ('program.exe') ('my args')
If strmark Showln ('Well, we have an error my friend... Exit code: ' + strmark )
Else ...
This works like a charm when the program itself has a problem or even if the user closes the Command prompt window.

Simple program that reads and writes to a pipe

Although I am quite familiar with Tcl this is a beginner question. I would like to read and write from a pipe. I would like a solution in pure Tcl and not use a library like Expect. I copied an example from the tcl wiki but could not get it running.
My code is:
cd /tmp
catch {
console show
update
}
proc go {} {
puts "executing go"
set pipe [open "|cat" RDWR]
fconfigure $pipe -buffering line -blocking 0
fileevent $pipe readable [list piperead $pipe]
if {![eof $pipe]} {
puts $pipe "hello cat program!"
flush $pipe
set got [gets $pipe]
puts "result: $got"
}
}
go
The output is executing go\n result:, however I would expect that reading a value from the pipe would return the line that I have sent to the cat program.
What is my error?
--
EDIT:
I followed potrzebie's answer and got a small example working. That's enough to get me going. A quick workaround to test my setup was the following code (not a real solution but a quick fix for the moment).
cd /home/stephan/tmp
catch {
console show
update
}
puts "starting pipe"
set pipe [open "|cat" RDWR]
fconfigure $pipe -buffering line -blocking 0
after 10
puts $pipe "hello cat!"
flush $pipe
set got [gets $pipe]
puts "got from pipe: $got"
Writing to the pipe and flushing won't make the OS multitasking immediately leave your program and switch to the cat program. Try putting after 1000 between the puts and the gets command, and you'll see that you'll probably get the string back. cat has then been given some time slices and has had the chance to read it's input and write it's output.
You can't control when cat reads your input and writes it back, so you'll have to either use fileevent and enter the event loop to wait (or periodically call update), or periodically try reading from the stream. Or you can keep it in blocking mode, in which case gets will do the waiting for you. It will block until there's a line to read, but meanwhile no other events will be responded to. A GUI for example, will stop responding.
The example seem to be for Tk and meant to be run by wish, which enters the event loop automatically at the end of the script. Add the piperead procedure and either run the script with wish or add a vwait command to the end of the script and run it with tclsh.
PS: For line-buffered I/O to work for a pipe, both programs involved have to use it (or no buffering). Many programs (grep, sed, etc) use full buffering when they're not connected to a terminal. One way to prevent them to, is with the unbuffer program, which is part of Expect (you don't have to write an Expect script, it's a stand-alone program that just happens to be included with the Expect package).
set pipe [open "|[list unbuffer grep .]" {RDWR}]
I guess you're executing the code from http://wiki.tcl.tk/3846, the page entitled "Pipe vs Expect". You seem to have omitted the definition of the piperead proc, indeed, when I copy-and-pasted the code from your question, I got an error invalid command name "piperead". If you copy-and-paste the definition from the wiki, you should find that the code works. It certainly did for me.

Lua - io.read sends me an echo back when I read from serial port - why?

I am writing a code in Lua to read from a serial port, but when I read I receive an echo back with the code :
print("Dragino Uart Test started\n")
while 1 do
serialin=io.open("/dev/ttyS0","r")
print(serialin:read()) --print the data
serialin:close()
end
When I open minicom to send him some data, I enable local echo than I type "text" and I see :
tteexxtt
Then I need to press enter to see my message in my lua script.
I am using a OpenWRT in a Dragino.
It seems that it is like a prompt command that you type every thing that you see and you need to press enter to send you command.
There is any other way to read and write to/from a serial port?
Can somebody help me please? Thank you so much!
The read method with no arguments reads a full line. That's why you need to press enter at the end of the text. Try reading one byte at a time with :read(1) or all of it with :read("*a").
I don know if this is still an issue to someone but maybe this helps a few people. Like lhf said :read(1) is a gread way of doing this. I had a few problems with :read("*a") though. In my opinion the easiest way of doing this is to append the answer piece by piece like:
rserial=io.open("/dev/ttyS0",'r')
lines = ""
repeat
local line=rserial:read(1)
if string.sub(line, 0, 3) == "OED" then --OED is here the stream ending. This can vary
EOD = true
rserial:close()
elseif line then
lines = lines .. line
end
until EOD == true
print (lines)

echo from php "as it goes"

what was the way to print results from a php script while it's printing stuff before the script ends? i tried to play with output buffer, putting sleep() between echos to test but the result is always showed after the script executes. Is it a browser-side thing too?
All you could do in your PHP script to try to flush all the current output to the user's browser is a call to ob_flush, but it actually depends on many other things as well.
The HTTP server has its own buffering, and the browser may not instantly render every packet it receives. It's like a long pipeline of buffers at different levels that all have to be flushed before you see anything in the browser, and the PHP output buffer is at the highest level.
yes you can do that this way
<?php
echo "hello senad";
flush();
sleep(20);
echo "meskin";
?>
PHP is server side. If you are making a web page, then the results will ALWAYS be shown on the client after the script ends and has been transmitted.
If you are running the script on your own computer, then I heard somewhere that one prints during execution and the other after the script is done. Try switching between print and echo and see how your results go.
There are 2 solutions:
1) Deactivate the output_buffering in php.ini
2) When using loops use this for example:
for ($i = 1; $i <= 3; $i++) {
echo md5(rand())."<br />";
flush();
ob_end_flush();
sleep(1);
}
PHP loads a page all at once then displays it. Use flush() to show output as the script loads.
Nice question.. when I want to do something like that (like loggin actions) I just use AJAX. And I know it's not probably what you wanted but hear me out.. I have had this problem as well 4 times so far and I've used AJAX and because of that I was able to put a preloader (which is really cool and helpful :))
By "use ajax" I mean if you have 4 actions to show up do 4 ajax requests. I know it's not the most elegant solution (as you do a lot of extra stuff) but it is a good design-wise solution.

Resources