DhruvPathak
DhruvPathak

Reputation: 43245

How can I view console output of a program in an editor like emacs or Vim in linux?

Lets say I have a simple program : (pseudocode)

for(i=0;i<1000;i++)
{
   print(i + "\n");
   sleep(1);
}


Output:
0
1
2

Is there way to view this output in an editor like emacs or Vi as it changes ? The behaviour I want is like "tail -f" done on a file being continously written to.

Upvotes: 2

Views: 683

Answers (5)

David Miller
David Miller

Reputation: 2219

This is actually built in to emacs :)

M-x auto-revert-tail-mode

From C-h f auto-revert-tail-mode :

When Tail mode is enabled, the tail of the file is constantly followed, as with the shell command `tail -f'. This means that whenever the file grows on disk (presumably because some background process is appending to it from time to time), this is reflected in the current buffer.

Upvotes: 4

zev
zev

Reputation: 3590

You can do something similar to the following using "ansi-term" and your own program (which you would substitute in place of the "top" process used in my example):

(progn 
  (ansi-term "/bin/sh" "top")
  (goto-char (point-max))
  (insert "top")
  (term-send-input))

Upvotes: 1

tripleee
tripleee

Reputation: 189477

In Emacs, there is M-x shell-command, as well as various specialized modes for monitoring the output from a command. You can also run a shell inside Emacs with M-x shell. It is also not hard to have a process produce output directly into an Emacs buffer from elisp; see the documentation for start-process (C-h f start-process RET).

Upvotes: 2

Hamza Yerlikaya
Hamza Yerlikaya

Reputation: 49329

          (start-process "my-process" "foo" "ls" "-l" "/user/lewis/bin")
               ⇒ #<process my-process<1>>

          ---------- Buffer: foo ----------
          total 2
          lrwxrwxrwx  1 lewis     14 Jul 22 10:12 gnuemacs --> /emacs
          -rwxrwxrwx  1 lewis     19 Jul 30 21:02 lemon

          Process my-process<1> finished

          Process my-process finished
          ---------- Buffer: foo ----------

Upvotes: 2

Diego Sevilla
Diego Sevilla

Reputation: 29021

In emacs at least, you can open a terminal window and have it at one side. Try M-xansi-termRET. Then you can divide the screen, using the different C-x<number>.

Upvotes: 2

Related Questions