Waiting for wine to finish running

旧巷老猫 提交于 2019-12-12 15:54:19

问题


My current script looks like this:

cd ~/.wine/drive_c/
echo "test123" > foo$$.txt
wine start "C:\foo$$.txt"
wineserver -w
echo "Wine is done!"

which works fine when only one program is running in wine at a time. However if I run this a second time, before the first program is done, both scripts will wait for each others programs to exit.

This does not work:

cd ~/.wine/drive_c/
echo "test123" > foo$$.txt
$(wine start "C:\foo$$.txt") &
wait ${!}
echo "Wine is done!"

as it will exit before you close the text editor.

I need to use the start command, because I want a file to be run with its default editor/viewer.


回答1:


To wait for the process started by wine to exit, you can pipe its output to another program. On my system, the following achieves the desired effect:

wine "program.exe" | cat
echo "program.exe has finished"

If you want to wait asynchronously:

wine "program.exe" | cat & pid=$!
# ...
wait $pid
echo "program.exe has finished"



回答2:


wineserver has a --wait flag which can be used to do exactly that.

However if you run multiple programs at once, it will wait for all of them to finish.




回答3:


What happens is that wine just asks wineserver to start the program and exits, and I have found no good mechanism to get notifications from wineserver about the processes that it spawns.

My suggestion would be to wait for the completion of the process started by wineserver using one of the methods in How to wait for exit of non-children processes, but you need to know its PID. Possible ideas: run wineserver -f -d | grep init_thread( and get PIDs from there, but I can see no easy way to find out which is which, to avoid race conditions, and to ignore noise; or try to find your process in the output of ps, but it's ugly, and definitely not robust.

If nothing better surfaces, you might want to suggest the addition of such a feature to the Wine devs (probably as a flag to wine).



来源:https://stackoverflow.com/questions/7205856/waiting-for-wine-to-finish-running

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