1

I've got a simple script which runs a windows program through wine with an argument (ie. myScript.sh = ~/some/path/someProgram.exe someArg). When I run it from its own directory it works fine:

cd ~/some/path
./myScript.sh

However if I try to run it from somewhere else:

cd /home/me
./some/path/myScript.sh

Because of How to execute script in different directory? I thought this might work:

/home/me/some/path/myScript.sh

but the script (or the resulting wine call) fails if I do anything other than run the script from the directory. Is there anyway to call the script from elsewhere without breaking it?

P.S. This isn't a permissions issue: the script has executable permission on for all users.

machineghost
  • 229
  • 2
  • 10
  • Create a `bin` dir in `/home/$USER` and add that to your path then put it in `bin` now you can run it from anywhere – George Udosen Dec 02 '17 at 19:08
  • 1
    Please edit your original question to show the script. It will help us help you. Otherwise we can only guess what is the problem. – sudodus Dec 02 '17 at 19:09
  • I think the link you gave should have an answer! Did you add `cd $(dirname $0)` as suggested in one the answers there? – George Udosen Dec 02 '17 at 19:10
  • @sudodus I shared the script in my question: `some/path/someProgram.exe someArg`is the entire script (although as I mentioned `someProgram.exe` gets run by wine), and the specific executable/argument is irrelevant to the issue (plus I rather doubt you're familiar with it anyway). – machineghost Dec 02 '17 at 19:25
  • @george Thanks, I tried adding `cd $(dirname $0)` to my script and moving it to `~/bin`, but no luck :( – machineghost Dec 02 '17 at 19:25
  • Maybe the specific executable/argument *is* relevant to the issue. You are right, I am probably not familiar with it, but someone else might be. Anyway, there must be something, that makes a difference. If you do not want to show it you must think about it yourself, and look at all the details: Is there 'some resource' in or under the folder of the script, that is used by the script. – sudodus Dec 02 '17 at 19:32
  • I'm not sure how to check for sure, but yes there very likely is "some resource" in the folder of the windows executable that is used by the executable. And since it's being run through WINE I'm sure it looks for those resources ... well however WINE looks for them (I don't know the details of that). The part I'm stuck on is that, however it looks for them, if I `cd` in first it can find them, but if I call the script from anywhere other than the executable's folder WINE can't find them. – machineghost Dec 02 '17 at 19:35
  • 1
    Would it help to use a full path to the `exe` file or maybe in some argument? – sudodus Dec 02 '17 at 19:39
  • No, it actually already was (you can't tell that from my pseudo paths so I'll edit the answer to add a leading `~/`). – machineghost Dec 02 '17 at 19:40

1 Answers1

2

I found a sloppy solution: I made things working by explicitly calling cd inside my script and then using wine explicitly to run the executable:

cd ~/some/path
wine someProgram.exe someArg

However it seems like there should be some way to make that work without explicitly calling cd, and I'll accept any answer that explains it. I won't accept this one since it doesn't truly answer my original question (because it does the cd it's not really running things "from elsewhere").

machineghost
  • 229
  • 2
  • 10