On Red console, I tried the following commands:
>> (print 0 call/shell/wait "sleep 5" print 5)
I think 0 would be printed first. After 5 seconds delay, 5 would then be printed.
In fact, both 0 and 5 were printed after delay of 5s. Why?
Note: sleep.exe is an external command.
The Red GUI console is buffering output too aggressively in order to provide fast output. A fix was just pushed, so it should now behave as you expect.
BTW, you don't need to enclose the whole line in (..), it does not change anything in the way that code line will be processed.
Related
I've got an AutoHotkey script that presents the following error when I try to run it again:
Could not close the previous instance of this script. Keep waiting?
It's a pretty simple script, with the following settings:
#NoEnv
#SingleInstance force
SendMode Input
DetectHiddenWindows, on
SetWinDelay, -1
I'm launching the script from the command line. I've tried using the /f / /force option and there is no effect.
I want the #SingleInstance Force behaviour described in the docs, which is described as:
Skips the dialog box and replaces the old instance automatically, which is similar in effect to the Reload command.
Turns out the problem was the SetWinDelay instruction.
From the docs:
Although a delay of -1 (no delay at all) is allowed, it is recommended that at least 0 be used, to increase confidence that the script will run correctly even when the CPU is under load.
A delay of 0 internally executes a Sleep(0), which yields the remainder of the script's timeslice to any other process that may need it. If there is none, Sleep(0) will not sleep at all.
When I had it set to -1 the script never had time to process other commands, including whatever exit command was sent to it.
Ensure SetWinDelay is greater than or equal to 0.
I'm using "Red Programming Language" version "0.6.4" on Windows and making a command line application.
I don't know much Red language and I don't understand many things. I did go over "work in progress" docs at (https://doc.red-lang.org/en/) before asking here.
I need to see the "Something, something..." on the screen for a bit (let's say 1 second) before the command prompt window closes.
Red []
; do something
print "Something, something..."
; pause 1 // not working
; sleep 1 // not working
quit
As in the code comments I've tried with pause or sleep but I get an error Script Error: sleep has no value. How to make it sleep?
Thank you.
The function you are looking for is WAIT. Try wait 1.
Using WAIT as prescribed by #MarkI above is the correct answer.
But I wanted to add below which should really be a comment but it looks nicer formatted!
The best way to explore Red/Rebol is via the console and making use of HELP
>> help pause
No matching values were found in the global context.
This means there is nothing defined for PAUSE (and ditto for help sleep).
So instead quote the word and it will search through all defined function documentation...
>> help "sleep"
No matching values were found in the global context.
>> help "pause"
No matching values were found in the global context.
Still no luck :(
OK lets try something related...
>> help "time"
... long list found items...
This now returns all functions that have some connection to "time" in their function spec/docs. In this list is WAIT function. However another HELP clearly shows it...
>> help "duration"
wait native! Waits for a duration in seconds or specified time.
Now we have it...
>> help wait
USAGE:
WAIT value
DESCRIPTION:
Waits for a duration in seconds or specified time.
WAIT is a native! value.
ARGUMENTS:
value [number! time! block! none!]
REFINEMENTS:
/all => Returns all events in a block
Hope that helps.
Im sure this is common but I was having trouble finding anything on google...
I am using Perl and I am running my program in UNIX. At one point in my program I am printing numbers which represent the number of regex matches found. Anyway the output is something like this..
1
2
3
4
5
etc..
It ends up being quite a long list, so if you want to get to the top or bottom of the output you have to do a ton of scrolling...
My question is how can I get the list output to update in realtime, so the list output would stay on one line. so that 1 changes to 2 changes to 3 etc..
Thanks for help!
It depends on a lot of things, but \r in a string should return the cursor to the beginning of the line.
Firstly, don't forget to unbuffer output in your Perl with:
$|=1;
Then try:
$(tput clear);
to put cursor to top of terminal window.
Try typing:
tput clear
into your terminal to see if that clears the screen and puts the cursor at top left. If not, try typing:
clear
to clear the screen and get cursor to "Home" position.
I'm writing a script in AutoHotKey, and I've stumbled upon an impasse. Right now I have a working GUI that involves checkboxes and dropdown lists. The program is a macro script for gaming-- the user checks which macros he wants running in the background, submits his options, and the program constantly evaluates various conditions and executes commands based on whether or not those conditions are satisfied.
The template of each one of the macros is this:
Loop:
PixelGetColor, color, 488, 778 ;gets pixel color of specific coordinate
if thecolor = 0x000000 ; if the color is black
{
SendInput {Raw}f ;sends the f command to use item
}
else sleep 20
goto, Loop
So the macro loops, evaluating a pixel each 2 miliseconds, and sending input if the if statement is fulfilled.
Here is the problem:
For each one of the macros that the user can check to run in the background, there is a different pixel color pinpointed, a different input sent, and a different coordinate to evaluate. How can I make an all-encompassing loop that takes into account the users check-box choices?
For example, if the checkBox = 1 (selected), I could be like:
if(%Box1%=1)
{
Run above code
}
But if the user checks 1 and 2, I'll have to evaluate other coordinates, too. Like thus:
if(%Box1%=1 & %Box2%=2)
{
Run above code
+
PixelGetColor, color2, 510, 778
if thecolor = 0x000000
{
Send 1
Sleep 20000
goto, start
}
else, sleep 20
I don't want to have multiple different loops that run one after another because it would too slow, and I don't want to have to do a huge branch of all the possible 'if' permutations.
Does anybody know what to do?
and I don't want to have to do a huge
branch of all the possible 'if'
permutations
The problem my friend is that that is the only solution.
You have to check the status of each checkbox, so there is no jumping that part.
If I could see your code I could send you an amendment for it, but you cannot paste the full code here. Try autohotkey.net/paste, and I will hopefully be able to help you.
I recently discovered that you can set breakpoints in Xcode that will print to the console and auto-continue -- meaning you can insert log statements without having to write NSLog() calls and recompile (on-the-fly logging, woot).
Only problem is that it seems to be a little limited in what you can display when doing a log.
It shows some tokens you can insert, like %B to print out some info about the current breakpoint or %H for the hit count.
I'd like to know if there's any way I can insert a time stamp in a particular format into the log line?
I tried playing with the "shell script" breakpoint action, but it told me that the date command didn't exist.... strange...
Any help would be awesome,
Thanks guys!
Read the GDB manual about Breakpoint Command Lists
You can give any breakpoint (or watchpoint or catchpoint) a series of commands to execute when your program stops due to that breakpoint. For example, you might want to print the values of certain expressions, or enable other breakpoints.
And in particular:
for example, here is how you could use breakpoint commands to print the value of x at entry to foo whenever x is positive.
break foo if x>0
commands
silent
printf "x is %d\n",x
cont
end
Does this answer your question?