How to quit after run IO.read(:stdio, :all) in the Elixir iex? - io

I need test some input data flow, and use 'IO.read', but after entering data i can't exit from this mode, CTRL-Z/X/C/D doesn't help (it terminates the whole iex). So how correct EOF command for this mode?
Thanks!

TL;DR: Use ^G followed by j, i [nn] and c [nn].
In both erl and iex shells you always might ^G to enter a “User switch command” mode. Type h for help there.
iex|1 ▶ IO.read :stdio, :all
^G
User switch command
--> j
1* {erlang,apply,[#Fun<Elixir.IEx.CLI.1.96155272>,[]]}
--> i 1
--> c 1
{:error, :interrupted}
iex|2 ▶
Sidenote: the correct EOF termination would be ^D in all the terminals. I honestly have no idea why it does not work as expected in erl/iex consoles.

Related

Sending Ctrl-L via dbus to terminal emulator

One can send text via dbus to the terminal emulator konsole as followed:
qdbus org.kde.konsole /Sessions/1 sendText "hello"
However I want to remotely clear the screen of the specified terminal window.
So I tried:
qdbus org.kde.konsole /Sessions/1 runCommand "clear"
Does partly what I want. Only problem: The screen doesn't get cleared when there is a process running.
In the terminal emulator, in this case the key combination "Ctrl + L" would do the job.
So I'm trying to send a string with escape characters for this shortcut.
Is this going to work? This, however doesn't do;
qdbus org.kde.konsole /Sessions/1 sendText "\033[2J"
(runCommand neither)
This is working for me:
qdbus org.kde.konsole /Sessions/1 sendText $'\014'
First, to produce a character from its octal code, the syntax "\033" would work in C but not in Bash.
Second, while "ESC [ 2 J" is a VT100 code to Erase Screen, it work for me only if I echo $'\033[2J', and that will not work if a command is running.
Third, Ctrl-L will work if a program is expecting input from a terminal (like irb or python do), but it will not work for a while sleep 1; do echo Still running; done loop.

What does this statement do on Linux?

I am trying to complete a lab report and I have just started using linux. I am really new to this ecosystem and I don't know how most of it works. I'm slowly learning from the labscript how to compile and execute C programs. However, after executing this statement
execute the output binary file using: $ ./myapp I am a student taking CMP 310
I lost the "$" sign and whenever I pressed enter this ">" would be printed before any statement and I couldn't execute or exit. If any of you could kindly explain what I did I would really appreciate it. Thank you.
You may have pasted an unmatched quote symbol, ' or " or a backtick ` and your terminal allows you to enter multiline statement and waits until you close the quote or backtick to evaluate it. To exit the multiline mode, either enter the closing character, or hit Ctrl-C, which in this case interrupts the input.
You have to paste only this part:
./myapp I am a student taking CMP 310
It tries to execute myapp executable file in your working directory (which ./ stands for), passing to it arguments I am a student taking CMP 310.
Me reproducing your problem:
16:45 $ "I have no idea what I am doing
> wut
>
>
> hello?
>
Most probably Ctrl+C will help you.
If you are working in GUI mode (not terminal) you can just close the window and open new shell session in new window.

bashscript Heredoc + FTP error

I try to do this
#!/bin/bash
ftp "$HOST"$3"/"$2"/" <<EOD
#toggle Interactive mode
prompt off
lcd $5"/"$4
mget "$4"*
exit
EOD
I get the following error
syntax error: unexpected end of file
When I changed it to or any other possibility
ftp "$HOST"$3"/"$2"/" <<<EOD
#toggle Interactive mode
prompt off
lcd $5"/"$4
mget "$4"*
exit
EOD
I get
./download.sh: line 31: 87621 Segmentation fault: 11 ftp "$HOST"$3"/"$2"/" <<< EOD
./download.sh: line 20: prompt: command not found
./download.sh: line 21: lcd: command not found
./download.sh: line 22: mget: command not found
I am not sure how to fix this. What am I supposed to doooo O_O
On my Mac, the segmentation faults were produced by the comments in the script. Removing the lines with the trailing # would make it work.
many interactive commands don't really deal well with piped input. maybe try http://www.columbia.edu/kermit/ftpscripts.html ?
that said, many others seem to have had success doing what you're doing (e.g. http://www.unix.com/unix-advanced-expert-users/4189-automated-ftp.html ), so maybe you just have a quoting problem? try changing the command (ftp "$HOST"$3"/"$2"/") to just cat to see if the shell is properly passing there here-doc to it?
this, too, may lend insight if you end up needing to supply a password: http://www.stratigery.com/scripting.ftp.html

How can I perform some commands on Intersystem cache from shellscript?

I want to perform some commands on Intersystem cache from shell script. One solution which I know is through making a config file but the problem is I dont know how to use config file through shell script. Is there any other solution for this...
for example what I have to run on cache is
csession instancename
zn "area"
area>D ^%RI
Device:some/device/path
Next: It should take enter
This can be accomplished from a Linux shell, simply keep a log of the commands you need to perform and then put them into a script. Here's an example of logging into Cache and writing "Hello world" -- note that this also assumes you need to authenticate.
echo -e "username\npassword\nW \"Hello world\"\nH\n" | csession instance
Note that every command you would have run manually is in there and separated by "\n", this is the character that represents the "Enter" key.
It is possible (for some operating systems) to run the Cache terminal in batch mode. For example:
echo: off
wait for:Username
send: SYS<CR>
wait for:Password
send: XXX<CR>
echo: on
logfile: Somepath\myFile.log
send: ZN "AREA"
wait for:AREA>
send: D ^%RI
wait for:Device:
send: some/device/path
wait for:Next:
send: <CR>
This is documented in the Intersystems cache terminal documentation, especially the using terminal in batch mode section and the terminal scripts section.
This is a very old question .. as I came across the same thing and so with a little R&D I found a work around to this problem. Which is very cool and simple.
Let's say I have this file (can be with any extension with each command in separate line)
myScript.scr
zn "%SYS"
for e="a","b","c" { w e,! }
So passing it to cache terminal in case of UNIX is using csession with linux PIPE (|) operator
cat myScript.scr | csession {instance_name}
Eg.
cat myScript.scr | csession CACHE
output
a
b
c
Note:
• Don't separate a command in multiple lines else `csession` will through <SYNTAX> error. (See how I wrote the *for* loop)
• Extra knowledge - Intersystem Ensemble supports *Cache Terminal Batch Mode* in Windows case... While in linux there is no cterm to take the scripts..
• But linux gives you a work around to do this ;).
Hope this helps you guys!! cheers :D

Unwanted control characters displaying in vimscript function output

[using MacVim 7.3 on OS X Lion]
I have a vimscript function which runs an external command. It's executing correctly, but the output displays (unwanted) control characters, such as [0m, [33m, [36m, and -1H. The relevant line in the vimscript function is:
exec ":!bundle exec rspec --color " . a:filename
Which produces:
:!bundle exec rspec --color spec/acceptance/user_logs_in.feature
[33m*[0m
Pending:
[33m User logs in [0m
[36m # the step 'the user "foo#test.host" exists' is not implemented[0m
[36m # [0m
Finished in 0.07121 seconds
[33m1 example, 0 failures, 1 pending[0m
Here's what the same command and output look like from the terminal, which is how I want it to display in vim:
$ bundle exec rspec --color spec/acceptance/user_logs_in.feature
*
Pending:
User logs in
# the step 'the user "foo#test.host" exists' is not implemented
#
Finished in 0.1161 seconds
1 example, 0 failures, 1 pending
Also, any time I execute and external command, vim displays -1H immediately after it. For example, if I type:
:ls<return>
I see:
:ls-1H
<rest of the output is as expected>
Any ideas on hiding those control characters and -1H.
(disclaimer: I'm very new to vim so please don't assume too much background knowledge on my part.)
Thanks.
Update 3/31/2012 # 17:32 PM
Sam Goldman's correct: MacVim doesn't know how to display colors, so it outputs the color codes.
I've switched to terminal vim (which supports colors, at least with iTerm), but using the version of vim that comes with MacVim, which is more up-to-date and is compiled with ruby support (among other things). The easiest way to do that is:
brew install macvim --override-system-vim
MacVim doesn't know how to display colors. Terminal vim will display the colors correctly, or you can add --no-color to your rspec command (or a .rspec file). I'm not sure about the -1H thing. Maybe some customization you have for your terminal?

Resources