How to run cygwin's startxwin from bashrc?

1k Views Asked by At

I use cygwin occasionally, where I start a mintty.exe from Windows 7, and then run the following command to start XWindows and an xterm:

/bin/run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe &

I tried to automate this xterm creation, by entering the following stanza at the end of my ~/.bashrc:

if [ `ps -ef | grep XWin | wc -l` -lt 1 ] ; then 
    echo "will start Xwin"
    /bin/run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe 
    sleep 300
fi

However, XWin is not starting, and the following error is printed:

Usage: /usr/bin/grep [OPTION]... PATTERN [FILE]...
Try `/usr/bin/grep --help' for more information.
bash: [: too many arguments

Can you suggest a way to start an xterm instance from Windows?

Notes:

  • I read the Cygwin FAQ and Googled for an answer.
  • Environment:
    Windows 7
    CYGWIN_NT-6.1-WOW64 1.7.33-2(0.280/5/3) i686 Cygwin

Edit

Based on @EtanReisner and @pjh comments, I changed the startxwin stanza to the following, which is working:

if ( ! pgrep XWin ) > /dev/null ; then 
    echo "will start Xwin"
    /bin/run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe 
fi
1

There are 1 best solutions below

0
On BEST ANSWER

Based on @EtanReisner and @pjh comments, I changed the startxwin stanza to the following, which is working:

if ( ! pgrep XWin ) > /dev/null ; then 
    echo "will start Xwin"
    /bin/run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe 
fi