简体   繁体   中英

Call vbscript from python

I'm trying to invoke a vbscript through python as follows

import os
import sys 
import pandas as pd
import numpy as np
rancsv = pd.DataFrame(np.random.randn(150, 5))
rancsv.to_csv('randomcsv.csv', sep=',')
os.system(r"C:\Users\v-2mo\Documents\Python Scripts\test.vbs")

However this simply gives an output of 1 in jupyter notebook and does not run the script.

The script when run directly, runs just fine.

What am I doing wrong?

os.system(r"C:\\Users\\v-2mo\\Documents\\Python Scripts\\test.vbs")

要么

os.system(r"C:/Users/v-2mo/Documents/Python Scripts/test.vbs")

answered well here https://stackoverflow.com/a/19114284/17889328 in short, .vbs opens ok in command prompt because shell associates with program wscriipt or cscript and runs it. run silently your program doesn't get the associationand doesn't know how to open. need specify "wscript filename.vbs" and / or run with shell eg "cmd /c..."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM