The forum

[Tutorial] Run command line programs while keeping work dir

Example on how to passthrough the current directory to a running windows program when using PlayOnLinux

Author Replies
brunoais Sunday 19 September 2021 at 16:59
brunoaisAnonymous

Intro

For this demo, I will provide an example on how to run pingo (image compressor) as a command line program with the help of PlayOnLinux.

Pingo doesn't really need the benefits of PlayOnLinux but other programs may.

In this case, I wanted to use a specific wine version which is not the default in my system and because pingo is very simple to install and have (just a self-conntained executable) it's easier to demonstrate and show how to do.

Here's the TL;DR commands to execute:

Create the shortcut file using PlayOnLinux interface

 

Edit the shortcut file

 

cd "$HOME/.PlayOnLinux/shortcuts"
sed -Ei 's/^cd "/EXEC_PATH="/' pingo
sed -Ei 's@^POL_Wine @cd "$COMMAND_PWD"\nPOL_Wine @' pingo
sed -Ei 's@^POL_Wine @POL_Wine "$EXEC_PATH/"@' pingo

Then create an executable file

cat << 'EOF' > "$HOME/.local/bin/pingos"
#!/bin/bash
COMMAND_PWD="$(pwd)"  /usr/share/playonlinux/playonlinux --run "pingo" "$@"
EOF
chmod +x "$HOME/.local/bin/pingos"

That's it. You can now run pingo normally and, for example, just give the file name

pingo "image.png"

If image.png exists in the current directory, pingo will spot it.

 

How it works (from what I can tell)

When playonlinux-bash is run, the current directory in the environment is already replaced. Because it is already replaced, there's no feasible way to get it back. Unless it's sent as a new environment variable. That is what the executable does.

Then, the PlayOnLinux shortcut script has a cd command that leads to the directory where the executable is. However, for an executable such as pingo, the current directory is very useful so the file paths don't have to be absolute, so I use sed to replace the cd command with setting a variable

sed -Ei 's/^cd "/EXEC_PATH="/' pingo

Because the PlayOnLinux executable has lost the path that was set, it needs to be reset. That's what the next line does.

sed -Ei 's@^POL_Wine @cd "$COMMAND_PWD"\nPOL_Wine @' pingo

Now, the current path is fixed and everything is (almost) set, what's missing is the executable. Because the executable is not in the current path, it needs to be called with the whole path. That's what the 3rd run of sed does:

sed -Ei 's@^POL_Wine @POL_Wine "$EXEC_PATH/"@' pingo

 

The executable in .local/bin gives the environment variable with the current path to PlayOnLinux, so it's available in the startup script.

After this, just execute pingo in the terminal and it will run for the current directory. No need to provide the full path.

 

I hope this was of help to you too!!!

 

This site allows content generated by members, and we promptly remove any content that infringes copyright according to our Terms of Service. To report copyright infringement, please send a notice to dmcayonlinux.com