My script must wait for a Windows process

Questions about Wine on Linux
Locked
Arikania
Level 2
Level 2
Posts: 12
Joined: Fri Mar 03, 2017 6:08 am

My script must wait for a Windows process

Post by Arikania »

Hi guys,
I am writing a script which launches a program under Wine 1.6.2 on my Linux Mint 17.1. but I need to make an injector wait for the Windows process to have started.

I know that I can wait for the winserver:

Code: Select all

while [ ! `wineserver` ]; do
  true
done

But it waits for the winserver, not for the child process. Also, in this context I cannot tell it which process to wait for when I have several wine processes running. How do I make my script wait for a specific Windows process to have started?
User avatar
Bob Wya
Level 12
Level 12
Posts: 3068
Joined: Sat Oct 16, 2010 7:40 pm

Re: My script must wait for a Windows process

Post by Bob Wya »

Arikania wrote:Hi guys,
I am writing a script which launches a program under Wine 1.6.2 on my Linux Mint 17.1. but I need to make an injector wait for the Windows process to have started.
That version, 1.6.2, of wine is years out of date... I'd recommend picking up the Ubuntu 14.04 WineHQ winehq-devel package (currently 2.2 - soon to be 2.3)...

I'd write a little wrapper script for the Windows program (in this example the builtin: winecfg.exe) you want to run:

Code: Select all

#!/bin/bash

# pre-entry stuff

wine winecfg.exe &
pid=$!
while ps --no-headers -p ${pid} &>/dev/null; do
  sleep 1
done

# post-exit stuff
Bob
Arikania
Level 2
Level 2
Posts: 12
Joined: Fri Mar 03, 2017 6:08 am

Re: My script must wait for a Windows process

Post by Arikania »

I've been very busy so it's only now that I can apologize for my late respons.

I installed Wine 2.3 in the meantime. Works fine indeed.

Inspired by Bob's example I got around it by using the pidof command.

Code: Select all

until `pidof mygame`; do
  sleep 1
done

sleep 7

But now the next issue popped up.

This strategy is in script which is run as user scriptowner, but it is to be run by all users. The whole script works fine, and wine itself start as scriptowner, but the program that it starts runs as the user who runs the script, so it runs as scriptuser, not as scriptowner. As a result, the calling script never receives that pid, and waits for ever.

How to I instruct wine to start mygame as scriptowner?


With regards,
Arikania
Level 2
Level 2
Posts: 12
Joined: Fri Mar 03, 2017 6:08 am

Re: My script must wait for a Windows process

Post by Arikania »

I need to rectify my previous post.

The first line of my code spells

Code: Select all

until [ `pidof mygame` ]; do
And it turned out that some other things had gone wrong with the script causing the malfunction. Scripting is trickier than I thought at first glance, apparently. Sorry for blaming wine, folks!

Thanks again for pointing me to version 2.3, Bob. Although I was taught to be suspicious about ppa's, I did add it to my update resources and I am quite happy with it. :D


Kindly,

Image
User avatar
Bob Wya
Level 12
Level 12
Posts: 3068
Joined: Sat Oct 16, 2010 7:40 pm

Re: My script must wait for a Windows process

Post by Bob Wya »

Arikania wrote:...
But now the next issue popped up.

This strategy is in script which is run as user scriptowner, but it is to be run by all users. The whole script works fine, and wine itself start as scriptowner, but the program that it starts runs as the user who runs the script, so it runs as scriptuser, not as scriptowner. As a result, the calling script never receives that pid, and waits for ever.

How to I instruct wine to start mygame as scriptowner?
...
Que? Not really quite sure what you are trying to say here!! :?

A code dump speaks a 1000 words though... 8)

Bob
lahmbi5678
Level 7
Level 7
Posts: 823
Joined: Thu Aug 27, 2009 6:23 am

Re: My script must wait for a Windows process

Post by lahmbi5678 »

Arikania, afaiu you want to run wine and its applications always under the same user account regardless of which users run the script. You could do this using su or "sudo -u". This probably isn't a good idea though, since wine is not really ready for multiuser service, in that configuration more than one user and more than one wineserver process may write data to the same wineprefix (.wine folder), which might cause odd effects. It may work, if you don't have many users and small "collision" probabilities.

The idea of wine is to run applications for every user in his/her own .wine folder, i.e. one user/wineserver process per wineprefix. Afaiu Codeweavers is offering multiuser support in its commercial CX Office, at least in a commercial environment you should consider buying some licenses.
Locked