我需要执行一个python脚本&传递一个输入文件&位置,也是输出位置。
这是我的尝试......
strPathAndFile = file name and path.
Set WSHShell = CreateObject("Wscript.Shell")
Return = WSHShell.Run("""CMD /C python c:\filepath\python.py"" " & -i strPathAndFile & "" "-o c:\output_folder\ &""", 0, True)
我认为它可能是我的括号?
答案 0 :(得分:0)
如果您系统地处理这些问题,这样的问题就更容易解决了:
Option Explicit
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Function qq(s) : qq = """" & s & """" : End Function
' Trying to identify the parts from the question
' """CMD /C python
' c:\filepath\python.py"" " &
' -i strPathAndFile & ""
' "-o c:\output_folder\ &"""
' Collect the parts
Dim sShell : sShell = "%comspec%"
Dim sPython : sPython = "python.exe" ' c:\Python25\python.exe, which("python2")
Dim sScript : sScript = goFS.GetAbsolutePathName(".\38081192.py")
Dim sInp : sInp = "d:\some\w h e r e\in.txt"
Dim sOut : sOut = goFS.BuildPath("z:\bitbucket", "out.txt")
' Combine them into a line by adding options and quotes **systematically**
Dim sCmd : sCmd = Join(Array( _
sShell _
, "/K" _
, qq(sPython) _
, qq(sScript) _
, "-i", qq(sInp) _
, "-o", qq(sOut) _
, "etc" _
))
WScript.Echo ">" & sCmd & "<"
输出:
cscript 38081192.vbs
>%comspec% /K "python.exe" "E:\trials\SoTrials\answers\37990815\vbs\38081192.py" -i "d:\some\w h e r e\in.txt" -o "z:\bitbucket\out.txt" etc<
在您之前打印sCmd。运行它有帮助。和
nRet = oShell.Run(sCmd, 0, True)
更容易检查。
第二个想法:
经过一些实验,我了解到python可执行文件应该不引用。所以
, qq(sPython) _
到
, sPython _