I enjoy running Postgres client "psql" under psql.el while interacting with a .sql file in a separate window. Sometimes, I want to use tab-completion within the the buffer running the psql process to find the name of an appropriate table name. However, I can not figure out how to cause the desired result.
A very related question has been asked here: https://superuser.com/questions/236574/how-can-i-send-a-literal-tab-to-bash-in-emacs-shell-mode
without any successful suggestions.
Thanks in advance!
SetJmp
Usually programs that designed for interactive use (when they own terminal) disable interactive features (like history for UP/DOWN, completion for TAB) when used in pipe.
Emacs usually use pipes for external processes. So interactive features are disabled.
Even if you send TAB, your client program does not interpret it for you as you want.
You can read man/help for your program and try force interactive mode by providing command line switch (like --login for GNU Bash).
To send TAB eval:
(defun my-comint-send-string (string)
"Send string to comint buffers. Useful for *compilation* read-only buffer."
(interactive
(list (read-input "Type string: " nil 'my-comint-send-hist-list)))
(comint-send-string (get-buffer-process (current-buffer)) string))
(define-key XXX-mode-map [C-return] 'my-comint-send-string)
and use such key sequence: C-RET C-q TAB RET.
But this may not work if buffering is enabled for stdio of your program (to flush input you must send \n too)...
Mostly same problem discussed at Bash autocompletion in Emacs shell-mode
NOTE M-x term use pseudo terminal so all interactive program work as desired. But in this mode you lose any Emacs editing capabilities...
Related
Trying to find the ANSI escape sequence for sending the keys ctrl+shift+6 in the format \u001b.. .
I recently tried switching over to only using Windows Terminal instead of SecureCRT/Putty but i'm having issues terminating Cisco telnet/console sessions that uses ctrl+shift+6 and then x.
The terminal does not seem to recognize this or isn't forwarding it the same way as SecureCRT/Putty because nothing happens. The session is established over term VTY100 if that has any use, and the SSH-session is initiated from a Zsh-shell in a Redhat7 jumphost, the base connection comes from my Ubuntu WSL2-box.
I think I found a possible workaround as Windows Terminals allows keybinding an ansi escape sequence, but I'm unable to figure out what the sequence would look like?
Send arbitrary text input to the shell. As an example the input "text\n" will write "text" followed by a newline to the shell.
ANSI escape sequences may be used, but escape codes like \x1b must be written as \u001b. For instance "\u001b[A" will behave as if the up arrow button had been pressed.
By default this exact keybinding is used by Windows Terminal to open a new tab but I removed that.
The question is
Trying to find the ASCII escape sequence for sending the keys ctrl+shift+6 in the format \u001b.. .
That's referring to ctrl^, which usually is 0x1e (hexadecimal) or 036 (octal).
Based on the comment which you quoted, that would be expressed as "\u001e".
If Windows Terminal assigns that to a different code, you might open a bug report, because its developers intend to imitate xterm.
I am testing some boards and the system used to test these is Tera Term. In Tera Term I use the Serial Port to send commands to the board in order to log in and run certain settings that I want.
Instead of typing these commands each time I test a board I want to create a program that sends these commands without the requirement to type them again and again each time.
Also I need to set a delay between each command as the system needs to to load between them.
Question
How can automate the typing of commands and delay between subsequent commands in teraterm?
I used the Tera Term Language (TTL) and created a macro which solved my problem. I used code to wait for a prompt from the system and then print out the command I wanted.
Here's a link to the TTL syntax:
http://ttssh2.osdn.jp/manual/en/macro/syntax/
Don't use Tera Term for that. It is not made for scripting, but rather for interactive use. Try to get a command line serial terminal emulator.
If you are on Linux you can use screen or there like.
If you are on Windows you can just write echo command > COM1 in a normal com.exe-window, according to this link: https://batchloaf.wordpress.com/2013/02/12/simple-trick-for-sending-characters-to-a-serial-port-in-windows/
(Replace COM1 with the name of your serial interface)
Make sure you don't have your Tera Term open while you use the echo-command, otherwise you'll get "Access Denied".
Is it possible to start a specific command of a Spring-Shell app and then return/exit the shell after the command is finished? Further is it possible to expose the exit code (System.exit) of the app to the operating system shell?
For my purpose i will take advantage of the plugin mechanism and the CLI-Annotations of Spring-Shell. But in general there is no human interaction with the app, instead a job scheduler (UC4) will start the app and check the exit code to generate an email in case of an exit code not equal to 0. On the other hand for manual tests by our customer, there is also the need of tab completion, usage help etc.
This behavior is already built-in (although we considered removing it, or at least make it optional). I see now that it is useful :)
Simply invoke the shell with your (sole) command and the shell will spin up, execute the command, and quit. Also, the return code of the shell already indicates whether there was an error or not (tried with an inexistant command for example). Of course, if your custom commands do not properly indicate an error (i.e. print an error message but perform a normal return) this will not work. You should throw an exception instead.
The behavior is back.
Run spring-shell with #my-script, like so:
java -jar my-app.jar #my-script
Where my-script is a file with your commands:
my-command1 arg1 arg2
my-command2 arg1 arg2
I am trying to implement an online terminal UI with jsch as backend.
I need to display the userinfo ie [username#Machine ~]$ information in the UI.
Since the outputstream simply sends the bytes, it is difficult to distinguish the userinfo with the real command output. Is there any way to distinguish the same?
In general, no.
If you have a shell channel, all you see is the output from the user's remote shell, including the prompt and the actual command output. You can try to parse that. In simple cases this will work, but in general it is impossible, as every command could output a prompt-like string.
The username should be known to you (it should be the same as you used for login), the server name is a bit trickier.
An idea worth exploring might be to set a special prompt delimited by character sequences which are unlikely to occur in "normal" command output – set the PROMPT variable in your shell.
You could circumvent that problem by not using actually a shell channel, but an individual exec channel for each command – but then you'll have to interpret commands like cd yourself and keep track of the current directory, and add a cd command before the actual command in each exec channel. You might want to have an sftp channel open in parallel to keep track of the directories (and list files, and so on).
I've previously used sql-oracle just fine in Xemacs on XP and vista.
However, now I'm using Postgresql psql on the command line but I kinda find it lame (as compared to using sql-* from within emacs)
So, I'm trying to get it(psql) working within xemacs(21.4.22) on windows. When I type
M-x sql-postgres ENTER, I get the following 3 prompts
User:
Database :
Server:
How come I am not prompted for password ? It presents a SQLi buffer but when I type my SQL in and press ENTER nothing happens. Also, I don't see any prompt (when I run psql from cmd.exe, I get the "databasename=#" prompt).
What gives ?
What am I expected to enter in the above prompts for a DB which is running on my box(localhost) and I know which DB that I need to connect to(I know what params to give psql but not in xemacs).
I tried the same with GNU Emacs (23.1.50.1 (i386-mingw-nt6.0.6001)) and the results
were similar :
A SQLi buffer but none of the SQL get executed and I didn't see a prompt for password.
Thank you,
BR,
~A
On Windows, psql, like ftp, is known to not work correctly under shell-mode as it's not using the stdin, stdout handles, but a console handle.
See Emacs FAQ for Windows / 7.2 Programs reading input hang