When I run the emacs text editor the process does not return so I cannot use the terminal which is obviously the default behavior.
I cannot find the switch or command in the man but I know it is something very simple.
How can I run emacs as a separate process so I can continue to use the terminal without opening a second one?
You can start any program in the background by appending an ampersand to the command, emacs &.
There's a whole framework for working with backgrounded processes, see for example man jobs, disown, fg, bg, and try Ctrl-Z on a running process, which will suspend it and give you the terminal, allowing you to resume that process either in the foreground or background at your pleasure. Normally when your shell closes, all those programs will end, disown allows you to tell a program to keep running after you end your session.
The emacs --help command is giving you a tip:
--batch do not do interactive display; implies -q
So run emacs --batch (or maybe emacs --executesomecommand ).
If you have a desktop (or some X11 display) and want emacs to open an X11 windows and give you back a shell prompt, run it in the background (e.g. emacs &) as many commented.
And I find very useful to start programs (or shells) within emacs, e.g. with Emacs commands: M-x shell, or M-x compile (for make etc...), or M-x gdb for a debugger.
You usually start one single emacs at the beginning of a working day. You could use emacsclient (or set your EDITOR environment variable to it) for other editions using the same emacs.
I'd like to add that Windows does have an equivalent to *nix's & for starting programs in a separate process:
start /b emacs Main.hs
Related
Is there a way that I can free my terminal from running the gVim process w/o quitting gVim so that I can continue to use the terminal? I'd like to be able to
do something similar to what I do with emacs. With emacs I can either use the emacs [file] command to have the process run through the terminal, or I can use the runemacs [file] command to keep the terminal free.
I start gVim with the command:
gvim [file]
and then the terminal hangs until I :quit gVim. When I searched for an answer to this question on the web, people advised that the best thing to do was to use ctrl-z to suspend the vim process and then use fg to return. However, this fails to work for me in both command line and gVim mode. I'm using Git Bash for my terminal on Windows 7.
You could run gvim in background as any other process:
gvim [file] &
After executing this command you receive a message indicating the pid of the new process. When you end it you should receive a similar message on that shell.
Edit:
The ctrl-z/fg problem is probably related to windows. This question states that GitBash would create a new shell instead of returning to the current one, so it probably doesn't work as in Linux. A possible solution would be to run your commands from gVim, either calling the shell through :! on mappings, or plugins/commands (fugitive for git, :py or some plugin for python interpreter, etc).
does anyone know how to produce a similar result?(essentially tying the windows terminal to the open program)
For example, when you run "emacs" in bash (or another linux terminal) it will produce an output into the open terminal until the program is terminated (or silenced with emacs &)
I want to be able to reproduce this effect on windows, but have no idea how, running start(and similar commands) will only run the program in a new window, with a hidden command line, detached from the cmd line process.
You need the /B flag:
start /B myprogram
(Of course, this will only work with programs that actually use the console. If the program doesn't generate console output, this won't magically make it do so.)
You can do that by first installing Cygwin and then running emacs from Cygwin.
Cygwin is a collection of tools which provide functionality similar to a Linux distribution on Windows.
try typing edit into a windows command shell, it's actually a better program than notepad. there are versions of vi, emacs, for windows and dos, you could try any of them.
ftp://ftp.delorie.com/pub/djgpp/current/v2gnu/
http://www.vim.org/download.php#pc
I'm working with a tool right now that requires me to putty to a remote host, login, run a series of commands to start an engine, open a new window (and login again) to start a different engine, then open a third window (and again, login) to actually use the tool (leaving the engines running in those first two windows). I'd like to write a shell script to automate the process so that I could just open one window, type "sh whatever.sh" and be off and running, without physically opening the new windows and logging in again. However, I can't find a command to get me from one window to the next. Any thoughts?
You can just background the first processes by adding an ampersand (&) to the command line or pressing Ctrl+Z when it is running (and then enter bg to let the process continue, more information about that with jobs).
If that's not enough, you can create virtual shells with screen or tmux.
If you've redirected X (i.e. you can access GUIs over ssh), you can also just start a new window by executing your favorite (GUI) console program, like xterm, konsole, gnome-terminal, etc.
Are you familiar with jobs on linux?
nohup whatever_1.sh &
nohup whatever_2.sh &
nohup whatever_3.sh &
Or perhaps screen would be of use here:
https://serverfault.com/questions/25301/job-control-and-ssh
See also, nohup:
http://en.wikipedia.org/wiki/Nohup
The bash command opens a Bourne-again shell (bash) session.
Try typing in "konsole". That should open a new bash window and set the focus to it.
On my Ubuntu 18 I just type the command:
gnome-terminal
and a new shell opens... I don't like the above answers because xterm and konsole most likely not already be installed.
Shell script on target machine cannot be aware of putty windows on client machine.
Consider using Screen : http://www.gnu.org/s/screen/ - it is clean and powerful way.
I think you need command line window then write:
$ xterm
# new window started
If you need python in new window:
$xterm python
#now a window will shown with python shell
Another nice option from Xfce's terminal:
xfce4-terminal
I have a quick question about programming using Vim. I sometimes make a silly mistake in my program.
For example, the Python code below has an infinite loop (say foo.py . . . be careful when executing it!)
x = 1
while x == 1:
x = 1
You won't see any result, but find a fan inside your computer is becoming louder, and you need to stop executing this Python program. On a Unix shell, you can do it by pressing Ctrl-z. Or, on Emacs shell-mode, just pressing Ctrl-c Ctrl-z.
I know how to switch to shell-mode in Vim: :sh (then type python foo.py) or :!python foo.py. But I don't know how to stop a job on a shell from Vim without killing Vim itself. Does anyone know this?
Why can't you use <C-C>? By default, it sends an INTerrupt signal unless program is able to catch <C-C>. Vim handles <C-C> like any other <C-...> key, but python does not do this by default.
By the way, <C-Z> in unix shells suspends program while in the case mentioned above you need to kill it which is done using <C-C>. Suspend=pause executing (though most programs are not able to/do not need to handle SIGTSTP/SIGCONT properly).
pkill <process name>
or
ps -ef, find the process then kill -9 <process id> (this is safer)
How do you determine that vim is "killed"? The :sh command starts a shell which looks like your normal shell. When the shell exits (e.g. after Ctrl-D) you return to Vim.
I would like to open applications in cygwin, e.g. notepad etc, without the shell blocking. Is there a way of doing this?
For example, typing in notepad myfile.txt will open notepad, and the cygwin shell will be unavailable until notepad is closed. I'd like cygwin to remain responsive whilst notepad is open.
If you are using some UNIX shell such as sh, then
notepad &
should work.
Remember: If you're using another shell, then other rules apply. cmd won't block for GUI applications, unless start /wait is used. But on UNIX-likes there is no distinction between console programs and GUI programs. They all run interactively on the console unless detached by starting them with & after the command.