POpen on WLS to call a native windows program

Hello everyone…after looking for solutions to my problem I’ve ended up here. nothing found on StackOverflow seemed to work for me.

let me explain my case:

  1. I’m on WLS running my python app/script…
  2. I want to run A native windows program that actually works from WLS terminal… this is the working command from WLS shell:

/mnt/c/Program\ Files/ChimeraX/bin/ChimeraX.exe "\\wsl.localhost\Ubuntu-22.04\home\pconesa\software\scipion\data\tests\relion_tutorial\volumes\reference.mrc"

Now this for me had 2 problems.
Problem A: The space at Program Files. No worries I can make a soft link in a path without spaces. Fine.

Second and unsolvable by me: No matter how I compose the path or is I use Shell = True…is that Path doesn’t reach the windows program “untouched”.

Example of my code:

from subprocess import Popen

file = r'\\wsl.localhost\Ubuntu-22.04\home\pconesa\software\scipion\data\tests\relion_tutorial\volumes\reference.mrc'
program = '/home/pconesa/software/ChimeraX/bin/ChimeraX.exe'
Popen([program, file])

On the windows side the program complains about the path:
No such file/path: \\\\wsl.localhost\\Ubuntu-22.04\\home\\pconesa\\software\\scipion\\data\\tests\\relion_tutorial\\volumes\\reference.mrc

Note that backslashes are doubled. I’ve tried many things “Shell=True”, Surrounding the path with double quotes (they end up being doubled as well)…

For me it seems that deep in the Popen… the python string for the file is use as str which actually doubles the backslash.

You mean WSL I expect windows subsystem for linux.

Can windows access the file?

In a cmd.exe terminal try dir of the path.

Thanks Barry, actually that is one of the 2 problems. And one is that quite often our files are links!!

yes links in WSL are not valid in windows.

The second thing was that for some reason backslash are doubled somewhere and I was blaming the backslashes all the time but it was incorrect. Maybe is just that ChimeraX is also python and when printing the path it doubles the backslashes?

This code works for me. Note I’m using realpath to avoid the link.

import os
from subprocess import Popen
file = "ScipionUserData/projects/TestMotioncor2AlignMovies/Runs/000498_ProtImportVolumes/extra/import_reference.mrc"
file = os.path.realpath(file)
file= os.path.abspath(file)
file = file.replace("/", "\\")
file = '\\\\wsl.localhost\\' + 'Ubuntu-22.04' + file
program = '/home/pconesa/software/ChimeraX/bin/ChimeraX.exe'


#Popen([program, file])
cmd = program + ' "' + file + '"'

print(cmd)
Popen(cmd, shell=True)

Sorry for the noise.

The \ will double if the repr() of the string is printed.

Windows allows the use if / in place of \ in the API calls.
Usually only the command line processing requires the .

So you could try removing the:

And see if the errors make more sense.