How to detach “git gui” started in “Git bash” on Windows?

夙愿已清 提交于 2020-01-12 03:52:09

问题


For example,

  1. I start "git bash";
  2. I navitage to certian directory;
  3. I start git gui&;
  4. I close the console window or press Ctrl+C.

Git-gui's window disappears. Even if I used git gui&disown. Even if it is not in foreground when I pressed Ctrl+C.

How to properly detach git gui from Windows console?


回答1:


To the benefit of the others I will give a more general answer related to both git bash and msys bash.

Solution 1: Detach without stdout

Assume you want to detach the app:

"C:\Program Files\MyApp\MyApp.exe"

which does not output any info you want to retrieve to stdout (or stderr).
use in your Windows bash shell:

cmd //c start //D "C:\\Program Files\\MyApp"  MyApp.exe arg1 arg2 

MyApp will run in a separate window and closing the calling bash shell will not affect it (by and large like a Linux daemon).

As noted, you can't read app messages unless they are dialog messages, therefore this solution fits to GUI applications. Anyway, if MyApp.exe is instead a Windows batch file like MyApp.cmd, it will call its cmd.exe host and log there: in short you will read outputs for the .cmd/.bat case.

Mac-like users

The cmd.exe window will flash-out for an instant. If this is not such cool for you(r users), in the above line replace cmd with cmdow, NirCmd or the likes.

Solution 2: Detach with stdout

If you want to read logs to stdout and stderr, use:

cmd //c start cmd //k  "C:\\Program Files\\MyApp\\MyApp" arg1 arg2 

This alternative is mostly advised if MyApp is a console application. Now you get a daemon with a "home". MyApp will run hosted by the second cmd.exe and you will see here its output.
For a GUI app you end out with two windows: MyApp window and the calling cmd window.

In both cases, exiting MyApp doesn't mean closing the cmd window; while closing the cmd window will only close MyApp console.

If the flashing punch strikes you, here you only need to replace the first cmd, the second is your daemon's visbile home.

Solution 3: Detach document centric applications

Some documents are closely related to some processing applications, via a mechanism resembling the Linux shebang syntax, but based on Windows' registry; so you open the document without calling the related application.

This behaviour can be emulated in bash and even in a detached style.

As for apps not needing to output to stdout and stderr, opening MyApp.doc with:

cmd //c start //D "C:\\Program Files\\MyApp"  MyApp.exe  "Path\\to\\MyApp.doc"

can be simplified to:

cmd //c start //D "Path\\to" MyApp.doc

As for apps needing stdout and stderr output,

cmd //c start cmd //k  "C:\\Program Files\\MyApp\\MyApp" "Path\\to\\MyApp.doc"

can be reduced to:

cmd //c start cmd //k  "Path\\to\\MyApp.doc"



回答2:


The following command works for me from "git bash":

git gui </dev/null >/dev/null 2>&1 &

I tried Ctrl+C, Ctrl+D and simply closing the console window. git gui stayed open in all cases.




回答3:


If the gitgui is already started, you can disown the job so that it doesn't end with the console:

disown -h <jobid>

If you want to do it when you start Git GUI (so you just launch and forget) there is nohup but for an unknown reason it's not in the binaries distributed by MsysGit




回答4:


Based on Antonio's answer I have figured out the following recipe:

cmd //c start //D "C:\Program Files\Git\bin" "wish.exe" "C:\Program Files\Git\libexec\git-core\git-gui"

It works, as can be tested by pressing Ctrl-D in the shell. The shell closes properly and git gui continues to work.

Drawback: this solution ignores the current directory and opens git gui in the C:\Program Files\Git\bin directory, not in the current directory.

One may argue that git gui on Windows remembers recent repositories so it's only a click away. True, but the question is: how to get a detached git gui in the current directory...

I have tried a few variants to fix the drawback, but nothing truly satisfying.

The ones below always ask what to open git gui with. Choosing "C:\Program Files\Git\bin\wish.exe" in the file selector works but has to be done every time.

cmd //c start //D "E:\\escapedwindowsstyle\\path\\to\\my\\git\\repo\\" "C:\\Program Files\\Git\\bin\\wish.exe" "C:\\Program Files\\Git\\libexec\\git-core\\git-gui"

cmd //c start "C:\\Program Files\\Git\\bin\\wish.exe" "C:\\Program Files\\Git\\libexec\\git-core\\git-gui"

Can anyone understand what happens and/or improve on that ?



来源:https://stackoverflow.com/questions/15763615/how-to-detach-git-gui-started-in-git-bash-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!