Help with VB script

Advertisement

Guest

Help with VB script

Hi,

I'm a total newbie at this and now my way around VB, I would like to have a script where I drop a folder, I extract the folder name and connect to a NAS where I want it to move this specific folder from one place to another with MV.

I started to make a test, but I get an error on row exec.StdIn.Write(
Set objArgs = WScript.Arguments
'WScript.Echo WScript.Arguments.Count

myFolder = Split(objArgs(0),"\")
intIndex = Ubound(myFolder)
WScript.Echo myFolder(intIndex)

Set shell = WScript.CreateObject("WScript.Shell")
'run (make it log to XML)
shell.Exec("""C:\Program Files (x86)\WinSCP\WinSCP.exe""")
' feed the commands
exec.StdIn.Write("option batch abort\n" + "open Nas\n" +"ls /share/HDA_DATA/Test\n" +"exit\n")

'wait until it finishes and collect its output
StdOut.ReadAll()
'optionally print the output
WScript.Echo(output)

     

Suggestions how I can get this to work ?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
27,226
Location:
Prague, Czechia

Re: Help with VB script

You need to store the result of shell.Exec call to variable exec taht you are using line below:
var exec = shell.Exec("""C:\Program Files (x86)\WinSCP\WinSCP.exe""")
exec.StdIn.Write("option batch abort\n" + "open Nas\n" +"ls /share/HDA_DATA/Test\n" +"exit\n")    

See documentation:
https://winscp.net/eng/docs/guide_automation_advanced#inout

Reply with quote

Guest

Thanks !

Set objArgs = WScript.Arguments
'WScript.Echo WScript.Arguments.Count

myFolder = Split(objArgs(0),"\")
intIndex = Ubound(myFolder)
WScript.Echo myFolder(intIndex)

Set shell = WScript.CreateObject("WScript.Shell")
'run (make it log to XML)
set exec = shell.Exec("""C:\Program Files\WinSCP\WinSCP.exe""")
' feed the commands
exec.StdIn.Write("option batch abort\n" + "open Nas\n" +"ls /share/HDA_DATA/'test\n" +"exit\n")

'wait until it finishes and collect its output
set output = exec.StdOut.ReadAll()
'optionally print the output
WScript.Echo(output)    

Now it starts winscp, but it does not login and do the ls part. and logging in manually and quit Winscp gives me Objext required: '[string:""]' on set output row.

Suggestions ?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,226
Location:
Prague, Czechia

Turn on session logging to file and inspect the log. If you do not find anything, post it here.
_________________
Martin Prikryl

Reply with quote

Advertisement

You can post new topics in this forum