[Wine] Program won't load fonts when run outside of installed dir

L. Rahyen research at science.su
Fri Feb 6 13:41:40 CST 2009

On 2009-02-06 (Friday) 14:38:43 Tofystedeth wrote:
> I'm trying get a couple pieces of software we use at work so we can replace
> a bunch of aging Windows machines with Linux boxes, but I'm having a little
> trouble.  I'll start with the potentially easiest problem first.
> One of the programs I'm trying to use is Lightspeed Virtual Terminal.  It
> runs fairly well with just a couple of glitches.  If I go to the directory
> it was installed to, either in the terminal or the file browser, and run it
> with the "Wine Program Loader" menu option, or 'wine lsvt.exe' it opens
> normally.  However, if I try to create a link or a launcher for it, it
> doesn't load the fonts and comes up looking awful.
> How can I fix this?

	Short answer: You are always supposed to run a Windows program 
from where it was installed. So, when creating a launcher use something like "wine 
start  /unix /path/to/your_program.exe" to start your program. If you want to 
create a link then link to script with "wine start /unix /path/to/your_program.exe" 
inside. Also you need to set WINEPREFIX environment variable in your script and 
convert with winepath all Unix paths in argument list for Windows program or it will 
not find files you want to open with it. This means, for example, that you cannot 
drag'n'drop file from Konqueror onto Windows program and expect it to open it. 
Please read long answer below if you want to solve all of above problems once and for all.

	Long answer: personally I dislike to write "wine start /unix ..." or "wine ..." or to cd to 
directory where a program is installed and think about current WINEPREFIX environment 
variable everytime I want to run Windows program; also I dislike that I cannot drag'n'drop 
in Konqueror a file onto Windows program (well, actually I can but result of such operation 
will not be useful) or can't use Unix path to a file I want to open it with Windows program.
Writing program-specific script for each Windows programs isn't and option, especially 
if you are using more than a few of Windows programs.
	To solve these problems I prefer to use support for misc binaries in the Linux kernel.
Using it you can run any Windows executable directly (in other words you will be able to run 
Windows executables exactly the same as you run native Linux executables - for example 
you can type in your terminal "/path/to/your_program.exe" and hit enter and your_program.exe 
will run). If you want to use support for misc binaries to run Windows programs in Linux I 
recommend you to create wrapper script /usr/local/bin/winestart with the following content
(actually this script is useful even if you don't want to use support for misc binaries).

# Copyright (C) 2009 L. Rahyen
# License: GNU LGPL version 2 or later
if [[ -z "$WINEPREFIX" ]]; then
  if [[ -n "`echo $APATH | cut -d/ -f1`" ]]; then
  } fi
  WINEPREFIX="`echo \"$APATH\" | sed 's/\/\.\//\//g;s/\/dosdevices\/.:\//\/drive_c\//;s/\harddiskvolume0/\/drice_c\//' |
  awk '
    n = split($0, a, "/drive_c/")
    printf("%s",  a[1]);
  if [[ ! -d "$WINEPREFIX" ]]; then
    unset WINEPREFIX
  } fi
} fi
while [[ "$1" != "" ]]; do
  FILE="`winepath -w \"$1\" | sed 's/ /\\ /g'`"
  if [[ -e "`winepath -u \"$FILE\"`" ]]; then
    ARGS="$ARGS $1"
  } fi
  echo "$ARGS"
} done
wine start /unix "$ARGS"

	Then save it and make it executable by running "sudo chmod +x /usr/local/bin/winestart". Then run this as root:

echo ':DOSWin:M::MZ::/usr/local/bin/winestart:' > /proc/sys/fs/binfmt_misc/register

	Make sure to put this command somewhere in your startup scripts (if you 
already have it there then change it accordingly); otherwise after reboot you will 
need to run it manually again. If you get "write error" then you already have DOSWin 
registered and you need to unregister it by running:

echo -1 > /proc/sys/fs/binfmt_misc/DOSWin

	...then run "echo ':DOSWin:M::MZ::/usr/local/bin/winestart:' > /proc/sys/fs/binfmt_misc/register" 

	Now you can run (for example) notepad like this:


	And even if you run your program in non-default Wine prefix it will run 
correctly. For running next few examples you need non-default Wine prefix so let's 
create one (unset command in second line is there just in case if you have non-empty
WINEPREFIX environment variable):

WINEPREFIX=~/.my-wine-prefix wineboot

	Now you can start notepad like this:


	Or like this:

cd ~/.my-wine-prefix/drive_c/

	...And in both cases winestart the wrapper script will detect that you are 
running notepad in non-default Wine prefix and will run notepad in ~/.my-wine-prefix 
Wine prefix (instead of using default ~/.wine). Obviously instead of notepad.exe you 
can run any program you want (usually you can find your Windows programs in
drive_c/Program\ Files directory).

	Another example:



cd ~/.my-wine-prefix/dosdevices/z:/$HOME/

	Both commands will run your-program.exe in ~/.my-wine-prefix Wine prefix. 
However if you explicitly specify Wine prefix using WINEPREFIX environment variable
it will override auto-detection. For example:

WINEPREFIX=~/.wine ~/.my-wine-prefix/drive_c/windows/notepad.exe

	This will run ~/.my-wine-prefix/drive_c/windows/notepad.exe in ~/.wine Wine 
prefix. Overriding auto-detection is useful sometimes for testing (for example you 
can run a program installed in ~/.my-wine-prefix using ~/.wine Wine prefix where it 
wasn't installed to see how well (or how bad) your program will work without 

	Support for direct execution of Windows executables will work with all file 
managers and shells so you can run all your Windows programs like native ones. 
Make sure to remove all associations in your file manager(s) with Wine (*.exe files) 
so file manager(s) can run Windows programs directly. Also you can specify in your 
launcher(s) Windows programs without prefixing them with "wine " or "wine start /unix" 
and/or specifying Wine WINEPREFIX environment variable (so in many cases you can 
use hard or symbolic links instead of launchers).

	Few more examples... Let's create a simple text file:

echo Text > ~/text.txt

	Now let's try to open it with notepad (or any other Windows program you like):

cd ~/.my-wine-prefix/drive_c/windows/
./notepad.exe ~/text.txt

	Notepad will successfully open ~/text.txt!

	If you are using Konqueror run it and go to "~/.my-wine-prefix/drive_c/windows/". 
You should see notepad.exe. Run another instance of Konqueror (or split Konqueror
window you just opened); make sure that you can see two Konqueror windows 
simultaneously. In another Konqueror window go to your home directory and find text.txt.
Now drag'n'drop text.txt to notepad.exe - Notepad will open text.txt for you.

	As you can see this script and support for misc binaries is very useful when used
properly. I hope this information will be helpful. If something doesn't work as you expected
let me know.

More information about the wine-users mailing list