I am running python 3.13.5 via PowerShell in windows 10. I can successfully run the folowing command, and now want to run it with a python script
& 'D:\realesrgan\realesrgan-ncnn-vulkan.exe' -i 'D:\test.png' -o 'D:\output.png'. How do you do this?
Below is the very long chain of gotcha's I have ran into trying to do this. I am posting this for others searching the internet as I feel like I am not the only one who has encountered this.
I tried:
import subprocess
args = ["& 'D:\realesrgan\realesrgan-ncnn-vulkan.exe' -i 'D:\test.png' -o 'D:\output.png'"]
result = subprocess.run(args)
And got the error FileNotFoundError: [WinError 2] The system cannot find the file specified because I needed to call it with shell = True. So I tried:
import subprocess
args = ["& 'D:\realesrgan\realesrgan-ncnn-vulkan.exe' -i 'D:\test.png' -o 'D:\output.png'"]
result = subprocess.run(args, shell = True)
And got the error The filename, directory name, or volume label syntax is incorrect. because I needed to use double slashes \\ and break it into a list at the spaces. So I tried:
import subprocess
args = ["&", "'D:\\realesrgan\\realesrgan-ncnn-vulkan.exe'", "-i", "'D:\\test.png'", "-o", "'D:\\output.png'"]
result = subprocess.run(args, shell = True)
And got the error & was unexpected at this time. because subprocess runs on the command prompt not the PowerShell. So I learned I needed to remove the & and also swap the single quotes ' to double quotes " so I tried:
import subprocess
args = ['"D:\\realesrgan\\realesrgan-ncnn-vulkan.exe"', '-i', '"D:\\test.png"', '-o', '"D:\\output.png"']
result = subprocess.run(args, shell = True)
And got the error The filename, directory name, or volume label syntax is incorrect.. What is the next gotcha that I am missing? At this point I know the command "D:\\realesrgan\\realesrgan-ncnn-vulkan.exe" -i "D:\\test.png" -o "D:\\output.png" works on the command prompt. I once got the .exe to register but it dropped the options I was passing in and I can't recreate the code that made that happen. There might be something with using subprocess.call() instead of subprocess.run()?