【发布时间】:2017-05-27 19:48:50
【问题描述】:
我有一个使用 Ctrl+j 运行的脚本
-
mongod(mongo 服务器) -
mongo(mongo 数据库) -
npm start(启动节点的网络服务器) - 在 Chrome 中打开
localhost:3000。
每个任务都必须在下一个任务开始之前准备好。比如mongod是mongo服务器,所以如果mongo在服务器准备好之前启动,就会报错。
这是我的脚本:
// Start or stop mongod, mongo, node
^j::
IfWinNotExist, npm // start everything up. This must be done in order, but the timing varies.
{
// Start the mongo server
Run, mongod.exe
WinGet, active_id, ID, A // Get the id of the window
GroupAdd, One, ahk_id %active_id% // Add the window to a new Group so we can minimize them all later
Sleep 1000 // This works, but the time varies. I'd like to replace it
// Start the mongo database
Run, mongo.exe
WinGet, active_id, ID, A
GroupAdd, One, ahk_id %active_id%
Sleep 1000 // I'd like to replace this
// Start the node server
Run, cmd.exe
Sleep 100
send, cd webroot{\}{enter}
Sleep 300
send, npm start{enter}
WinGet, active_id, ID, A
GroupAdd, One, ahk_id %active_id%
Sleep 1000 // I'd like to replace this
// Minimize all the cmd windows
WinMinimize, ahk_group One
// Always opens a new tab - but that's for another question...
Run, chrome.exe http://localhost:3000
} else { // shut everything down if they're already running
SetKeyDelay, 400
ControlSend, ,^cy{enter}, npm
SetKeyDelay, -1
Sleep 1000
WinClose, ahk_class ConsoleWindowClass
SetTitleMatchMode 2
ControlSend, ,^c, mongo
Sleep 1000
WinClose, ahk_class ConsoleWindowClass
ControlSend, ,^c, mongod
SetKeyDelay, 200,
Sleep 1000
WinClose, ahk_class ConsoleWindowClass
}
Return
// Bonus for anyone that's interested in using this script.
// Recycle the node server in the background
!`::
SetKeyDelay, 200
ControlSend, ,^c y{enter} npm start{enter}, npm
Return
有没有办法等到服务完全启动后再进行下一个任务?
编辑:更改了代码结构,使重要部分更靠近顶部。
【问题讨论】:
-
您是否查看过此处描述的
WinWaitClose:autohotkey.com/docs/commands/WinWaitClose.htm 您可能还喜欢此处描述的WinWaitActive(也可以在获胜无效时找到):autohotkey.com/docs/commands/WinWaitActive.htm
标签: mean-stack autohotkey