简体   繁体   English

仅在程序启动后才继续批处理脚本

[英]Continue batch script only after program has booted

I have a batch script (yes I know batch is awful, no I don't care) that checks my VM's on the local machine to the ones stored on my USB, if they're out of date, it updates them, then boots them. 我有一个批处理脚本(是的,我知道批处理很糟糕,不,我不在乎),该脚本会检查本地计算机上的VM与USB上存储的VM是否一致,如果它们已过期,则会对其进行更新,然后启动他们。 I use multiple machines at uni, so this makes it easier to ensure the VM I'm working on are always the latest. 我在uni上使用多台计算机,因此可以更轻松地确保正在使用的VM始终是最新的。

When I open them like this; 当我这样打开它们时;
PATH "%PROGRAMFILES%\\VMware\\VMware Workstation\\"
START vmware.exe -x "%USERPROFILE%\\Desktop\\VMs\\VM1\\VM1.vmx"
START vmware.exe -x "%USERPROFILE%\\Desktop\\VMs\\VM2\\VM2.vmx"
START vmware.exe -x "%USERPROFILE%\\Desktop\\VMs\\VM3\\VM3.vmx"
It causes the VM's to open in separate windows, rather than tabs of the same window for easy switching. 这会导致VM在单独的窗口中打开,而不是在同一窗口的选项卡中打开以方便切换。

The workaround I came up with is to boot the VMware program first, then when I open the .VMXs, they all open as tabs in the same window. 我想出的解决方法是先启动VMware程序,然后在打开.VMX时将它们全部作为选项卡打开在同一窗口中。
The problem is that the VMware program sometimes takes a long time to open. 问题在于,VMware程序有时需要很长时间才能打开。 Similar to Photoshop's loading splashscreen, but instead with no visual indicator, VMware opens up to 20 seconds after the icon has been clicked, or it has been summoned with a script. 与Photoshop的加载初始屏幕类似,但是没有可视指示器,VMware在单击图标或使用脚本进行调用后最多打开20秒。

So finally, here is my question. 最后,这是我的问题。
Is there a way to make a batch that waits for the program to open before continuing? 有没有办法使批处理在程序继续运行之前等待其打开? I know by omitting START I can stop the batch until the program closes, but obviously this is useless for my purposes. 我知道通过省略START可以停止批处理,直到程序关闭,但这显然对我没有用。

If all else fails, I may just have to include a 30 second timeout and hope it's enough. 如果所有其他方法都失败了,我可能只需要包括30秒的timeout并希望它足够。

I don't think there's any reliable way to do this. 我认为没有任何可靠的方法可以做到这一点。

If you have a program that you need to open and then wait for a certain state to change in the program before doing something else, that state could be set by any arbitrary operation running on any thread spawned by the application. 如果您有一个需要打开的程序,然后等待该程序中的某个状态发生更改,然后再执行其他操作,则可以通过在应用程序产生的任何线程上运行的任意操作来设置该状态。 There would be no way to know when the application had set that state unless you were able to somehow communicate with the program to query or be notified of its state. 除非您能够以某种方式与程序进行通信以查询或通知其状态,否则将无法知道应用程序何时设置了该状态。

Theoretically if you knew enough about what the program was doing internally you could monitor the thread count or file system accesses or something to determine roughly when it had changed to the desired state, but just using a timer would be much much simpler. 从理论上讲,如果您对程序在内部所做的事情了解得足够多,则可以监视线程计数或文件系统访问,或大致确定何时将其更改为所需状态,但是仅使用计时器会简单得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM