Home > Back-end >  Insert variable in subprocess.Popen
Insert variable in subprocess.Popen

Time:08-05

how can I pass the variable TargetFile in the Popen command?

import subprocess


TargetFile = 'D:/CG_CONTENT/TEXTURES/Concrete_Rough_ujxlfi2dy_4K_surface_ms/ujxlfi2dy_4K_Albedo.jpg'

subprocess.Popen(r'explorer /select,"TargetFile"') #doesn't work

Thank you.

CodePudding user response:

Popen(["explorer", "/select", TargetFile])

CodePudding user response:

This was the solution I found.

import subprocess

TargetFile = r'D:\CG_CONTENT\TEXTURES\Concrete_Rough_ujxlfi2dy_4K_surface_ms\ujxlfi2dy_4K_Albedo.jpg'

subprocess.Popen(r'explorer /select,"' TargetFile '"')
  • Related