Unable to redirect output from VBA with cmd in hidden mode

51 views Asked by At

Am trying to redirect output from cmd to a text file using Wscript.shell script. It works when cmd window is in active mode. But doesn't work with cmd windows style is 0 (hidden mode).

Dim objShell : Set objShell = CreateObject("WScript.Shell")
Dim cmd : cmd = "cmd /K sftp  " & sftpusername & "@" & sftpserver & " > output.txt"
Oresult = objShell.Run (cmd, 0, false)

The output file is empty. However, when I change the window style to 1, I can see the data on output file.

0

There are 0 answers