How to simply ignore output from a program when called as an external one in vim? - vim

I can dump the output content from my external command in the main window, I can disable "Press ENTER or type command to continue" and simply store it in a register.
But how do I call an external command in vim (it can be any program, apt-get, etc) and simply avoid it creating a buffer window if an output? Simply IGNORE the output from a external command I ran? I just want to call the command from vim. The command starts a simple webserver (listening on port 8080) and I have to press ctrl+c to stop it and move away from the external command buffer.
I tried silent before !cmd, it works, but I would like to stop the process my external command created right after it was started.
EDIT: I changed my mind about the simple webserver. I another situations, just doing like the suggestion accepted answer it works.

Pipe output to /dev/null:
:!cmd &> /dev/null
Use silent as you mention to get rid of the Press ENTER or type command to continue:
:silent !cmd &> /dev/null
Read this page for more on hiding this message.

Related

Press enter key in a shell script and ignore nohup output

I have a basic shell script that I made for deploying my packages...
I am facing 2 issues while executing the command
nohup /home/username/wildfly/wildfly-20.0.1.Final/bin/standalone.sh &
Its keeping me frozen and saying the below
nohup: redirecting stderr to stdout
If I run this command in a normal way, I should press ENTER and the process will keep running in background fine.
So, my question is there any way to simulate that ENTER key stroke?
I have also an scp command to copy a file to another server and it's required to enter password after executing it, is there a way to enter the password through myscript.sh and press ENTER key?
scp /home/username/myfile.war 0.0.0.0:/home/username/myfile.war
Thanks in advance :)
It shouldn't actually freeze you, just look confusing because it has the "nohup:" message after the prompt for your next command (and then you need to press enter to get a new prompt). But you should be able to avoid the message by redirecting stdout and stderr yourself:
nohup /home/username/wildfly/wildfly-20.0.1.Final/bin/standalone.sh >/dev/null 2>&1 &
This sends both stdout and stderr to /dev/null, so nohup doesn't have to deal with them.

Vim run shell and see output

I'm trying to run an unsaved buffer in a shell command and have a history of the output
console.log("test")
Then, :w !node does what is expected, test is outputted, but once I click enter, the output disappears, and doesn't even show in :messages:
How can I find it?
If you open a Vim buffer and type in one or more shell commands each on "his" own line. Like:
ls /home
ls /root
Then you can type the command:
:%!bash
and not only will it run the commands on each line one after the other, it will also overwrite the buffer with the output of each command in chronological order, then you can do whatever you want with it :-)
I hope it was helpful :)
BTW: if you want to run a command in Vim and get the output in your buffer, then you can just double tap the exclamation mark in NORMAL MODE and the command line in the bottom will show
:.!
then you just type in your command and press enter. :)
easy peachy lemon squeeze :)
note: I learned that last one by mistake
What :w !cmd does it pipes your current buffer contents into cmd's stdin. When you don't need this you should simply execute :!cmd instead.
:messages serve to show an important log data printed by specially dedicated :echom[sg] command, not some random stuff from terminal windows. So the output from "node" process will not and should not ever get there.
You can put the process' stdout into the current buffer by using :r[ead] command, e.g.
:r !node

Cygwin terminal input disappearing after quitting vim

Using Cygwin, I tried creating and editing a file in Vim:
touch test | vim
This is obviously a mistake; something like vim "$(touch test)" has a better chance of actually working. Nevertheless, this command throws the error:
Vim: Warning: Input is not from a terminal.
And after this, Vim opens and I exit the program with :q. Any subsequent commands I enter into the terminal are hidden from view until I restart Cygwin.
Why is this?
You don't understand what does a pipe | do in shell.
Pipe will take the pervious command's stdout as stdin to next command, in a subshell.
Your touch foo doesn't generate any output, what do you expect to happen? same for vim "$(touch test)".
If you want to create a file and open it in vim in one shot, you can try:
touch foo && vim foo
If you want to edit it with vim anyway, actually, you can simply just:
vim foo
then save the buffer after your editing.

Disable pagination on the command line

I am trying to write a script using the python module pexpect that will connect to a server and execute commands like you are typing at the command line.
So for example, you can have something like:
child = pexpect.spawn('/usr/bin/ssh user#example.com')
child.sendLine('ls -al')
or whatever command you want to send. It will act like you are typing in a terminal.
In my script, I am trying to run a command using the sendLine() API that essentially dumps out a bunch of info to the command line. But there is a pagination that requires there to be another command where you have to press a key to continue to get to the next command.
So for example:
[Some info]
--------------- To continue, press any key. To quit, press 'q'. ---------------
[Some more info]
Is there a way that I can turn pagination off or a command I can send before I try to dump the info to the command line to turn it off?
In Linux:
You can use redirection to skip the pager(more or less). If it is important to display the output on screen, the output can be redirected to tee.
For example in man ls; ls, the man command expects the user to press q for termination and then ls is executed. To execute both the commands simultaneously without user intervention, it can be done as man ls | tee; ls. If displaying the output is not mandatory, it can be redirected to /dev/null as well.
For additional help, please specify the exact command that you are trying to execute on the remote server.
In Python: When using pexpect, the user activity can be automated if the intermediate output is known in advance. You can use expect function to wait for a particular output and then take necessary action(for example using sendLine).

silent keyword not working in vim for external commands

I was working on a vimscript that executes lgrep silently. However, the silent keyword would not work for any external command that is run. lmake, lgrep, etc all still dump their output despite the silent keyword used before the command.
How do I suppress the output??
Example:
:silent lgrep -R a *
The above command would dump out all results, forcing the user to press enter. I can't reproduce his problem on my machine, in bash/zsh/tmux/screen/terminal/iterm/vim 7.3/vim 7.4/anything. Any tips would be appreciated.
UPDATE:
I still have no idea what the problem is, but I found a workaround that goes something like this:
silent !grep -Rn a * >/tmp/lgrep_output.txt
lf /tmp/lgrep_output.txt
Run the raw external grep command (not lgrep) silently (this successfully suppresses the output, but :lgrep doesn't), redirecting the output to a file. Then load the file into the location list (lf /tmp/lgrep_output.txt)

Resources