简体   繁体   English

从 python 调用 vbscript

[英]Call vbscript from python

I'm trying to invoke a vbscript through python as follows我正在尝试通过 python 调用 vbscript 如下

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.然而,这只是在 jupyter notebook 中给出了 1 的 output 并且不运行脚本。

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.在这里回答得很好https://stackoverflow.com/a/19114284/17889328简而言之,.vbs 在命令提示符中打开正常,因为 shell 与程序 wscript 或 cscript 关联并运行它。 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..."需要指定“wscript filename.vbs”和/或使用 shell 例如“cmd /c ...”运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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