0

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.

8
  • 1
    Try instead reading from stdout: stackoverflow.com/a/69367057/478884 Commented Feb 6 at 16:50
  • @TimWilliams Thanks for the response. But I have a requirement to run cmd in hidden mode. can that be achieved though Stdout, if so could you share some instruction on that.
    – Manoj
    Commented Feb 7 at 5:16
  • Sorry I missed that exec always needs to run with a visible window - stackoverflow.com/questions/32297699/… Commented Feb 7 at 5:48
  • Maybe try providing a full path for output.txt Commented Feb 8 at 0:49
  • I tried that too, but when cmd is not visible there is not output. the file is empty.
    – Manoj
    Commented Feb 8 at 7:39

0

Browse other questions tagged or ask your own question.