Why does terminfo disagree with read? [duplicate] - terminfo

This question already has an answer here:
Why is terminfo[kcuu1] = '\EOA'?
(1 answer)
Closed 5 years ago.
I'm using xterm. If I type infocmp $TERM | grep end, I see that kend=\EOF. However, if I type read, and then the End key, I see that the sequence \E[F is generated. This seems to be a problem with other keys, too.
Surely the values should be identical??

The terminal can be set on a special mode to send keystrokes from the keypad. You can set that mode by running tput smkx and unset it by tput rmkx.

Related

Why there is no output on asking input from user in lua using sublime text [duplicate]

This question already has answers here:
Can't send input to running program in Sublime Text
(5 answers)
Running Code in Sublime text 2 ( Mac OS X )
(1 answer)
Closed 2 years ago.
On initiating this program i got no output, not even the compiler asked me for input
You're supposed to submit text, not images.
That being said: Your script is fine, but Sublime pipes output to the editor, but isn't a full terminal, so doesn't allow input.
#! /usr/bin/env lua
io.write( 'Enter a number : ' )
local a = io.stdin:read('*n')
while a < 200 do
print( 'value of a :', a )
a = a +1
end
You'll have to open an actual terminal, cd into the relevant directory, then run your script.
chmod +x NAME_OF_SCRIPT.lua && ./NAME_OF_SCRIPT.lua
or
lua NAME_OF_SCRIPT.lua

plink - dealing with special charters in password [duplicate]

This question already has answers here:
How can I escape an exclamation mark ! in cmd scripts?
(4 answers)
Closed 3 years ago.
All,
I have a script that is using plink to connect to ~300 routers. I last used it to update a password for an admin account. Short is, password containing ! is failing.
I can SSH to the router with the password containing ! just can't connect using plink. I have tried replacing ! with %21. Tried escaping with ! and ^!. Nothing is working.
Thoughts?
Yea, that was a lot of nonsense to end-up with double ^
So. Escape ! with ^^
Example
plink -pw abc^^!

while [[ condition ]] stalls on loop exit

I have a problem with ksh in that a while loop is failing to obey the "while" condition. I should add now that this is ksh88 on my client's Solaris box. (That's a separate problem that can't be addressed in this forum. ;) I have seen Lance's question and some similar but none that I have found seem to address this. (Disclaimer: NO I haven't looked at every ksh question in this forum)
Here's a very cut down piece of code that replicates the problem:
1 #!/usr/bin/ksh
2 #
3 go=1
4 set -x
5 tail -0f loop-test.txt | while [[ $go -eq 1 ]]
6 do
7 read lbuff
8 set $lbuff
9 nwords=$#
10 printf "Line has %d words <%s>\n" $nwords "${lbuff}"
11 if [[ "${lbuff}" = "0" ]]
12 then
13 printf "Line consists of %s; time to absquatulate\n" $lbuff
14 go=0 # Violate the WHILE condition to get out of loop
15 fi
16 done
17 printf "\nLooks like I've fallen out of the loop\n"
18 exit 0
The way I test this is:
Run loop-test.sh in background mode
In a different window I run commands like "echo some nonsense >>loop_test.txt" (w/o the quotes, of course)
When I wish to exit, I type "echo 0 >>loop-test.txt"
What happens? It indeed sets go=0 and displays the line:
Line consists of 0; time to absquatulate
but does not exit the loop. To break out I append one more line to the txt file. The loop does NOT process that line and just falls out of the loop, issuing that "fallen out" message before exiting.
What's going on with this? I don't want to use "break" because in the actual script, the loop is monitoring the log of a database engine and the flag is set when it sees messages that the engine is shutting down. The actual script must still process those final lines before exiting.
Open to ideas, anyone?
Thanks much!
-- J.
OK, that flopped pretty quick. After reading a few other posts, I found an answer given by dogbane that sidesteps my entire pipe-to-while scheme. His is the second answer to a question (from 2013) where I see neeraj is using the same scheme I'm using.
What was wrong? The pipe-to-while has always worked for input that will end, like a file or a command with a distinct end to its output. However, from a tail command, there is no distinct EOF. Hence, the while-in-a-subshell doesn't know when to terminate.
Dogbane's solution: Don't use a pipe. Applying his logic to my situation, the basic loop is:
while read line
do
# put loop body here
done < <(tail -0f ${logfile})
No subshell, no problem.
Caveat about that syntax: There must be a space between the two < operators; otherwise it looks like a HEREIS document with bad syntax.
Er, one more catch: The syntax did not work in ksh, not even in the mksh (under cygwin) which emulates ksh93. But it did work in bash. So my boss is gonna have a good laugh at me, 'cause he knows I dislike bash.
So thanks MUCH, dogbane.
-- J
After articulating the problem and sleeping on it, the reason for the described behavior came to me: After setting go=0, the control flow of the loop still depends on another line of data coming in from STDIN via that pipe.
And now that I have realized the cause of the weirdness, I can speculate on an alternative way of reading from the stream. For the moment I am thinking of the following solution:
Open the input file as STDIN (Need to research the exec syntax for that)
When the condition occurs, close STDIN (Again, need to research the syntax for that)
It should then be safe to use the more intuitive:while read lbuffat the top of the loop.
I'll test this out today and post the result. I'd hope someone else benefit from the method (if it works).

Objective-C: Determine which file has performed an NSLog [duplicate]

This question already has answers here:
How to print out the method name and line number and conditionally disable NSLog?
(13 answers)
Closed 9 years ago.
Say I have 10 different implementation files that are run in an chaotic order, and in each of them I have an NSLog(#"Log");, and when I run the program I will get 10 Log's to my console output, but how can I know which one was logged by which file? I'm searching for something like
`In someFile1.m: Log`
`In someFile3.m: Log`
`In someFile2.m: Log`
`...`
And so on and so forth. Is that possible?
You can use preprocessor macros for that, take a look at this example:
NSLog(#"In %s - %s:%d someObject=%#", __FILE__, __func__, __LINE__, someObject);
Here's what's available:
https://developer.apple.com/library/ios/qa/qa1669/_index.html
You can use __FILE__ macro:
NSLog(#"%s",__FILE__ );
Which outputs filename:
2013-10-16 20:49:17.536 ABC[3637:a0b] /Users/who/where//DeviceViewController.m

&& Equivalent in Powershell [duplicate]

This question already has answers here:
What are the PowerShell equivalents of Bash's && and || operators?
(4 answers)
Can I get "&&" or "-and" to work in PowerShell?
(13 answers)
Closed 3 years ago.
In bash I use ./task1.sh && ./task2.sh to run task1, and then run task2 as long as task1 did not return an error code. When I try .\task1.bat && .\task2.bat in Powershell I get the error "The Token && Is not a valid separator in this version."
Is there an equivalent for && in Windows Powershell?
This is the closest I can get:
.\task1.ps1 ; if($?){.\task2.ps1}
I think the closest equivalent would be:
.\task1.bat;if($lastexitcode -eq 0){.\task2.bat}
Also, Powershell has -and which you might want to try, but it is not really the same.