0

I need to execute a python script & pass it a input file & location, also a output location.

This is my attempt...

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)

I think it could be my brackets?

Jammy
  • 41
  • 5
  • Welcome to Stack Overflow! I've edited your question a bit. If you disagree with my edit, you can roll it back. Click on the "edited ... ago" link; this takes you to the edit history, where you have a rollback option. That said, I think you should [edit] your question yourself; as has been pointed out by others, it might help us if you'd tell us what error message you were getting. Good luck and enjoy your stay! – S.L. Barth is on codidact.com Jun 28 '16 at 17:49

1 Answers1

0

Problems like this are more easily solved, if you approach them systematically:

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 & "<"

output:

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<

Printing the sCmd before you .Run it helps. And

nRet = oShell.Run(sCmd, 0, True)

is much easier to check.

cf. here, here, and here

On second thought:

After some experiments I learned that the python executable should not be quoted. So

, qq(sPython) _

to

, sPython _
Community
  • 1
  • 1
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • Thanks for the reply.... because I am writing the code in QlikView and not a native VBscript tool, I'm unable to work through your solution / fault finding. I thought it's just a case of me getting the brackets or quotes in the wrong place? – Jammy Jun 29 '16 at 11:49