How 'exec 1-; exec 2-' work?

2010-09-03 Thread Oleksandr Gavenko
I develop gtk app under Windows and in order to run it I need start 
Cygwin X Windows.


To start X Windows I use Makefile rule:

.PHONY: cygwin-startx
cygwin-startx:
XWin -multiwindow 

But when I invoke this target in native GNU Emacs
by M-x compile in *Compilation*  buffer I see XWin output and compilation
not complete. So next M-x compile Emacs prompt

  A compilation process is running; kill it? (yes or no)

I intuitively change command to

  exec 1-; exec 2-; XWin -multiwindow 

and now Emacs compilation finished and server work in background.

I really don't  understand what magic exec do.

Can anyone point me?


--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Re: How 'exec 1-; exec 2-' work?

2010-09-03 Thread Eric Blake

On 09/03/2010 02:47 AM, Oleksandr Gavenko wrote:

I intuitively change command to

exec 1-; exec 2-; XWin -multiwindow 



I really don't understand what magic exec do.


How could it be intuition if you don't know what it does?  A better 
description would be calling it what it was to you at the time - black 
magic copied from some online example you found.



Can anyone point me?


'exec' with just file redirections makes those redirections affect the 
current shell and all subsequent processes started by the shell.  1- 
is a POSIX-mandated redirection for closing stdout; likewise 2- for 
closing stderr.  By closing stdout and stderr before starting XWin, you 
are making it so that XWin no longer ties up your terminal.


By the way, you could run this instead:

XWin -multiwindow - 2- 

and get the same effect without the 'exec'.

And none of this is cygwin-specific.

--
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple