I'm new to Kotlin and I'm playing with the for loop, in Kotlin Script (*.kts file) I have this in the file:
for (i in 1..5) print("$i, ")
I did think it would print the number 1 through 5 separated by commas in one line like this:
1, 2, 3, 4, 5,
But instead I don't get any output on the command line. I'm running this on a Mac via
kotlin ranges.kts
If I put anything behind this single for loop, like a seperate println() or if I replace the print in the loop with println, it works and gives me output.
I don't get this behaviour. Can anyone explain this to me?
Edit1:
Versions:
kotlin: 1.3.71
MacOS 10.15.4 (Catalina)
This has nothing to do with the for loop and everything to do with print. It works if you add System.out.flush() at the end of the script. By default, writes to System.out (which print uses under the hood) don't always flush, and its likely that the Kotlin script runner isn't flushing the standard output stream before exiting.
This is also why using println works, as you noted -- if you look at the implementation of println in PrintStream, you'll see that it does flush its internal text and character output streams.
I created issue https://youtrack.jetbrains.com/issue/KT-38263.
Related
Here are UDVs, which I use as loop variables:
Here is the For-Each definition.
When I run this from starting = 1 to ending = 11, it only runs 1, 2, 3, 4.
Then it stops.
Here is loop #4.
This shows that variable status_1, status_2, ... , status_11 are all defined.
The question is: why is status_5 and onwards not running?
Either you made a typo/copy paste issue and one of the variables have an extra non-printable character like whitespace or line break
Or there is something else preventing the test from execution like CSV Data Set Config which has run out of the values or error has occurred and Thread Group is configured to stop in that case of whatever.
Check jmeter.log file for any suspicious entries, if nothing unusual is there - increase JMeter logging verbosity and check it again.
Under normal circumstances the ForEach Controller works as expected:
would like to get some help on a c project i am currently working on. I have a string/array of output to the terminal, but somehow the standard terminal is too small for my output. Even after i manually expand the window of the console the output is still cut off, instead of printing in a single line, it just gets cut off and go to the next row automatically.
hope to get help.
I think that the only way to correct this is by splitting your one-line output in multiple lines, using "\n" at the end of every line.
By doing this you can control when and where it has to write in the next line, and you can make it look more like you wanted to.
I am trying to print the - print statements in python behave step files, meanwhile i do not want to print the traceback errors. I used behave.ini file with stdout_capture=False setup. It helps to print the print statements in the step file but along with it, it also prints the traceback errors. I do not want this to print and want only output the print statements mentioned in the step files. Is there any way to do it ?
I used below command.
behave exmaple.feature --logging-level= ERROR
Try to add this to behave.ini
stderr_capture = no
refer the below documentation: https://github.com/behave/behave/blob/master/docs/behave.rst#configuration-files
How do you extract data from gdb so you can examine it in another program?
I am using gdb to debug a program. To see what is in array udata, I have created a source file called printudata with the following contents:
print udata[0]
print udata[1]
print udata[2]
...
print udata[143]
From within gdb I can execute that using source command and get output like this:
(gdb) source printudata
$399 = 1
$400 = 2.5
$401 = .3-10
...
$542 = <number>
So far, that is the best I can do for examining memory.
The only thing I can think of to do with this is (learn regular expressions and) strip off everything up to the equal sign so I can paste this into a spreadsheet which will tell me whether it's correct.
Is this the really the best way to get output from gdb? I am learning all this on my own and only have the basic, free tools that come with Linux (and am a beginner with all the above listed technologies)
You can print an array if it is really an array like this:
p udata
But, if udata is really a pointer, then you can use a cast to make gdb print it like an array.
p *(double(*)[144])udata
If you really want the line at a time output of your current "script", you can define a function and use a loop:
define print_udata
set $i=0
while ($i < 144)
p udata[$i]
set $i=$i+1
end
end
To log the output to a file, you can enable/disable logging:
set logging on
...gdb commands...
set logging off
The output will be in a file called gdb.txt.
In addition to the above, gdb has the "output" and "printf" commands. These don't enter the value into the value history, and they let you control the output much more precisely.
gdb has built-in scripting in both its own scripting language and in python. You can even script GDB from within a python program. You can use any of those options to write the data to a file.
More information about python & gdb here.
Is there a combination of VT100 escape sequences that will allow my C program to print something like:
Waiting......
to a console, in such a way that the dots appear one by one? Essentially, I want a command that will let me insert an extra '.' in front of a newline that has already been sent.
I'm looking for a quick one-liner for linux; it does not have to be portable. ncurses is overkill for this.
you can add ESC[K (clear to end of line) to ESC[A (up one line), and print your new line text
an example using Python:
import random, time
for _ in range(100):
print('\x1b[A\x1b[Kthis will print each line cleanly: %d' %(random.randint(0, 100000)))
time.sleep(0.1)
if you really want to be neat about things, use ESC7 (save cursor) and ESC8 (restore cursor)
then, you write your line and at the end of it you use ESC7. at the beginning of the print statement, you use ESC8. note, unless you turn off automatic newlines, this will not work at the bottom of your tty. it will work on all lines but the bottom.
import random, time
print('this will print each dot cleanly: \x1b7')
for _ in range(10):
print('\x1b8.\x1b7')
print('print more foo: %d' %_)
time.sleep(0.1)
for shell scripting (bash), you would use printf "..." without a \n, or echo -n
An easy way to do this is to use the escape sequence
"\x1b[A"
to move the cursor up one line. Then, re-print the "Waiting..." message, with one more dot than the last time.