When I put a println statement, it just outputs the code. What idiotic thing am I missing?
Set the default interpreter to spark (scala) or set it for the paragraph explicitly with %spark.
Related
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.
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.
I am using a makefile where there is a line like
VAR=$(MVAR) command1;
Now when command1 executes i want VAR to retain the value what is being assigned by MVAR which is required for the successful completion of command1.
But unfortunately VAR contains some default value while executing command1, ie VAR is not able to hold the value assigned during assignment while executing command1.
if same command i run in any of the shell the value of VAR is retained and command1 gets executed successfully.
Nearly tried everything to run it on makefile.
Can somebody please explain me the reason behind this behavior in gnu makefile and possible solution. I am using Linux as OS and ksh as shell for Makefile.
If you are talking about a command in a rule, just add (or move) a semicolon:
VAR=$(MVAR); command1
But I suspect there may be more involved. If this doesn't work, please give us more context (e.g. the makefile and some information about command1).
what sort of thing are you expecting MYVAR to be set to? If it contains spaces or other characters meaningful to the shell, what you are doing won't work. You could try quoting it:
VAR='$(MVAR)' command1
and see if that works better.
Also, this depends on your shell being a standard POSIX bourne-shell derivative (sh, bash, ksh, zsh all qualify; the Windows cmd processor does not).
Have you tried VAR:=$(MYVAR)? (i.e. := instead of =)
This forces VAR to be assigned the value immediately, rather than being lazily evaluated.
For educational reasons I have to exploit an C-Code
The Programm set the egid first, and then the vulnerability with the system("/usr/bin/..."); Command.
So I made an 'usr' executeable in my Home-Directory and set the Path to the Home PATH=$HOME:$PATH
And I want to change the IFS Variable in the bash to /: export IFS='/'
Unfortunatelly, when i call the C-Programm: my exploit doesn't work
Is anybody able to tell me what is wrong?
Add the IFS as part of your program's call to system(). System executes the code with /usr/bin/sh -c. So you can do similar to what you'd in the shell prompt.
system("export IFS='/'; /usr/bin/cmd");
Note that once the child process is terminated, the IFS set will no longer be available in the parent.
I suppose we are studying at the same university, because I am currently confronted with the same problem. I don't want to give you the whole solution, because that would be too easy =)
Your IFS variable is not ignored, but it doesn't work as you might think. When you call the C-Programm there is an additional output in the shell, which refers to the lesspipe. With the information in this link and this german link you are able to solve the challenge1 ;)
I understand if I write a bash script I can get the return value, but is there anyway to get the return value without scripting, and just command line?
Yes, the same way you'd do in a Bash script. Run your program like this:
./your_program; echo $?
In light of the invalidation of the previous answer (good point, Carl Norum), let me re-phrase my comment as an answer:
BASH stores the return value of the previously run command in the variable $?. This is independent of the programming langauge used to write said command (the command can also be a shell internal).