2

I'm trying to launch a Bash Shell window that should immediately start a Windows Application. It's the Bash Equivalent of "cmd /c MyApplication.exe". MyApplication is a Windows Console application.

I tried a couple of things that do not seem to work. Or just result in a hanging bash shell...

 sh.exe --login -I MyApplication.exe
 sh.exe MyApplication.exe

Creating a MyApplication.sh that starts MyApplication.exe seems to work, but is not desireable, as I'd like to include the start-up script in a debug macro.

3 Answers3

4

The Bash equivalent is bash -c <command>. This information is easily found in the man page.

This, for example, is what is used when you enter a custom command for a SSH session.

Now, you do need to keep in mind that Bash is not a Windows shell. If <command> is located in your working directory, you need to invoke it as ./<command>.

If you just toss it the file as the first argument, Bash will try to execute it as a Bash script.

Also, if you really want Bash, use bash. sh could be anything.

Daniel B
  • 62,883
  • Thanks! I was looking for the sh.exe pages, but that didn't help. The combination of -c and ./ did the trick. – jessehouwing Jan 05 '15 at 15:47
  • 1
    bash -c only works for single argument command lines. cmd /c echo hello world prints "hello world" but bash -c echo hello world prints nothing. You can run bash -c "echo hello world", but this gets problematic when your arguments contains spaces and/or quotes. – OLL Dec 05 '18 at 14:48
1

End the command with a & like this

sh.exe MyApplication.exe &
Nifle
  • 34,446
  • 1
    To expand on that: the reason this works with cmd is that it has hacks to detect that the application being started is a gui one and fake the return code rather than waiting for the process to actually terminate and return a status. – psusi Jan 05 '15 at 15:29
0

In Cygwin, you might investigate cygstart in the 'cygutils' package.

From the man page:

Let Windows start a program or open a file or URL.

<...>

EXAMPLES

  Start Bash in a new window

   $ cygstart bash

   Open the Cygwin website in your default browser:

   $ cygstart http://www.cygwin.com

   Print a text file

   $ cygstart --print README.txt

   Open a Word document in a maximized window

   $ cygstart --maximize ~/projects/whatever/design.doc

Try cygstart --help

pak
  • 187