0

Part of my python program uses subprocess to open a vbs script.

path = os.sep.join(['C:','Users',getpass.getuser(),'Desktop','Program','build','exe.win32-3.6','vbs.vbs'])

subprocess.call([sys.executable, path])

But instead of executing my vbs script it tries to run it as a python code and gives me: NameError: msgbox is not defined. And when i manually run vbs script it works.

I want python to normally execute the vbs script. Not run it as python code.

3
  • So what exactly is your question? Commented Aug 10, 2017 at 19:19
  • sys.executable is the Python interpreter. Use the name of the executable you want to run the .vbs file with instead. Commented Aug 10, 2017 at 19:23
  • Possible duplicate of Executing a vbs file with arguments created by python Commented Aug 10, 2017 at 19:26

2 Answers 2

0

sys.executable points to the system's Python executable. In your case that'd probably be something like C:\Python27\python.exe. You should print it out and see for yourself.

To execute VBScripts, you'd want to use C:\Windows\system32\wscript.exe.

Additionally, using os.path.join() is more suited to the task than os.sep.join().

So you'd end up with:

system32 = os.path.join(os.environ['SystemRoot'], 'system32')
wscript = os.path.join(system32, 'wscript.exe')
path = os.sep.join(['C:','Users',getpass.getuser(),'Desktop','Program','build','exe.win32-3.6','vbs.vbs'])
subprocess.call([wscript, path])
Sign up to request clarification or add additional context in comments.

Comments

0

This is exactly what you are telling subprocess to do. From the docs

sys.executable

A string giving the absolute path of the executable binary for the Python interpreter, on systems where this makes sense. If Python is unable to retrieve the real path to its executable, sys.executable will be an empty string or None.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.