我在 Windows 中使用 git bash 来运行一些 nodejs 脚本,但是每当我使用它并退出时,git bash 会自动将该进程转移到后台并且不允许我使用该端口,除非我使用命令终止该端口。
但是当我使用 cmd 时,它工作得很好,进程不会在后台运行,也不需要终止在端口上运行的进程,为什么?
最佳答案
vscode issue 24452 中也有报道导致 node-pty issue 7 .
均引用git-for-windows/git issue 227
官方维护者Johannes Schindelin (dscho) 3 个月前(2017 年 6 月)提到:
Alas, it is not. In v2.13.1, I changed the way Ctrl+C works and the problem described in this ticket still persists.
Any help would be very much appreciated.
The problem comes from different implementations of Ctrl+C processing in cygwin/msys applications.
POSIX applications are ready to process "signals" in most cases, but often ignores console events.
2018 年 4 月更新,Johanes just added :
After testing this with my fix for #1491 (which will hit https://wingit.blob.core.windows.net/files/index.html soon, so you can verify my claim, and you should, if you are interested in this issue) it would appear that there is no longer a freeze (although quite a bit of delay if you hit Ctrl+C tons of times).
参见 git-for-windows/MSYS2-packages commit f4fda0f :
msys2-runtime: revamp Ctrl+C handling yet again
This thing again...
Background: when you hit Ctrl+C on Linux or macOS, a signal (
SIGINT) is sent to the foreground process and its child processes. This signal can be intercepted by installing a signal handler for this specific signal.
On Windows, there is no precise equivalent for this system.Instead, the Ctrl+C is translated by the current ConHost (i.e. the container running the Console processes) to a
ConsoleCtrlevent that is sent to all processes attached to that Console. If any of these processes installed a handler viaSetConsoleCtrlHandler(), they can intercept that event (and avoid exiting or doing some cleanup work).On Linux and macOS (and every Unix flavor, really), processes can also be killed via the
killexecutable, which really just sends a signal to the process, typicallySIGTERM. Processes can intercept that signal, too. To force processes to terminate, without giving them any chance to prevent that,SIGKILLcan be sent.
There is no equivalent forSIGTERMon Windows. To emulateSIGKILLon Windows,TerminateProcess()can be used, but it only kills one process (unlikeSIGKILL, which is sent also to the child processes).In Git for Windows, we struggled with emulating
SIGINT,SIGTERMandSIGKILLhandling essentially since the beginning of the efforts to port Git to Windows.
评论的其余部分描述了最初的尝试和新的尝试。
这可能会进入 Git 2.18(2018 年第二季度)。
Windows 版 Git 后台作业的另一个原因:新命令 git maintenance (Git 2.29(2020 年第四季度))。
但这随着 Git 2.31(2021 年第一季度)的推出而改变,并且引入了计划维护任务以支持其 native 计划方法不是“cron”的平台。
参见 commit 3797a0a , commit 2afe7e3 (2021 年 1 月 5 日)和 commit 16c5690 , commit 31345d5 (2020 年 11 月 24 日)Derrick Stolee ( derrickstolee ) .
(由 Junio C Hamano -- gitster -- merge 于 commit b2ace18 ,2021 年 1 月 15 日)
maintenance: use Windows scheduled tasksCo-authored-by: Eric Sunshine
Signed-off-by: Eric Sunshine
Signed-off-by: Derrick Stolee
Git's background maintenance uses cron by default, but this is not available on Windows.
Instead, integrate with Task Scheduler.Tasks can be scheduled using the 'schtasks' command.
There are several command-line options that can allow for some advanced scheduling, but unfortunately these seem to all require authenticating using a password.Instead, use the "
/xml" option to pass an XML file that contains the configuration for the necessary schedule.
These XML files are based on some that I exported after constructing a schedule in the Task Scheduler GUI.
These options only run background maintenance when the user is logged in, and more fields are populated with the current username and SID at run-time by 'schtasks'.Since the
GIT_TEST_MAINT_SCHEDULERenvironment variable allows us to specify 'schtasks' as the scheduler, we can test the Windows-specific logic on other platforms.
Thus, add a check that the XML file written by Git is valid when xmllint exists on the system.Since we use a temporary file for the XML files sent to '
schtasks', we prefix the random characters with the frequency so it is easier to examine the proper file during tests.
Instead of an exact match on the 'args' file, we 'grep' for the arguments other than the filename.There is a deficiency in the current design.
Windows has two kinds of applications: GUI applications that start by "winmain()" and console applications that start by "main()".
Console applications are attached to a new Console window if they are not already associated with a GUI application.
This means that every hour the scheduled task launches a command window for the scheduled tasks.
Not only is this visually obtrusive, but it also takes focus from whatever else the user is doing!A simple fix would be to insert a GUI application that acts as a shim between the scheduled task and Git.
This is currently possible in Git for Windows by setting the<Command>tag equal toC:\Program Files\Git\git-bash.exewith options "
--hide --no-needs-console --command=cmd\git.exe", followed by the arguments currently used.
Sincegit-bash.exeis not included in Windows builds of core Git, I chose to leave out this feature.
My plan is to submit a small patch to Git for Windows that converts the use ofgit.exewith this use ofgit-bash.exein the short term.
In the long term, we can consider creating this GUI shim application within core Git, perhaps incontrib/.
git maintenance现在包含在其 man page 中:
BACKGROUND MAINTENANCE ON WINDOWS SYSTEMS
Windows does not support
cronand instead has its own system for scheduling background tasks. Thegit maintenance startcommand uses theschtaskscommand to submit tasks to this system. You can inspect all background tasks using the Task Scheduler application. The tasks added by Git have names of the formGit Maintenance (<frequency>). The Task Scheduler GUI has ways to inspect these tasks, but you can also export the tasks to XML files and view the details there.Note that since Git is a console application, these background tasks create a console window visible to the current user. This can be changed manually by selecting the "Run whether user is logged in or not" option in Task Scheduler. This change requires a password input, which is why
git maintenance startdoes not select it by default.If you want to customize the background tasks, please rename the tasks so future calls to
git maintenance (start|stop)do not overwrite your custom tasks.
关于windows - 为什么安装在 windows 中的 git bash 在后台运行脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46512056/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%