Search code examples
pythonpython-3.xsubprocessos.system

run an executable file through python


I am working on running an executable through python to connect to a cyberarc vault. When i run executable in command line it works, but in python i am not able to get the result.

I have tried both os.system and subprocess but no help.

Please help

import os
import subprocess
prg = "D:\File\CyberArk\ApplicationPasswordSdk\CLIPasswordSDK.exe"

arg = "GetPassword /p AppDescs.AppID=XXXXX-X-1 /p Query=XXXXXXXXXXXXXXXXX;Object=XXXXXXXX-USERID /o Password"

passw = os.system('prg arg') # I have this and as well below with subprocess

passw = subprocess.Popen([r'prg', 'arg'])

print(passw)

In command line below will work -

"D:\File\CyberArk\ApplicationPasswordSdk\CLIPasswordSDK.exe" GetPassword /p AppDescs.AppID=XXXXX-X-1 /p Query=XXXXXXXXXXXXXXXXX;Object=XXXXXXXX-USERID /o Password

Solution

  • It tries to execute prg arg in the CMD, simpy remove the '

    passw = os.system(prg + " " + arg)

    should work