1

How can I insert data directly from cmd into text1? I tried this but get wrong output just some numbers...

Dim com As String
Private Sub Command1_Click()
Dim sCommand As String
sCommand = "dir"
Text1.Text = Shell("cmd.exe /k" & sCommand)
End Sub
Vladimir
  • 63
  • 2
  • 10
  • `Shell` returns a status code, not the output of the command. Use [WshShell](http://stackoverflow.com/a/8906912/3484251) instead. Also it couldn't have worked anyway, you need a space after `/k` – z̫͋ Jun 12 '14 at 16:08

1 Answers1

1

Your code is very close. Check out this answer and it should point you in the right direction. Getting command line output in VBScript (without writing to files) Basically you need to get the Shell command in to an object i.e objShell and then use the .StdOut.ReadLine() method.

Community
  • 1
  • 1
Sean W.
  • 863
  • 5
  • 14
  • 1
    The cmd parameter /k will prevent the anything from being returned to the caller. Nothing is returned until the window is closed. If the OP uses the /c switch as in the answer you referenced the OP will get the results they probably expect. – jac Jun 12 '14 at 19:33