I have a VB6 program that needs info that I could find by running a command line command. Is there a way I could shell the command, then grab the output (other than writing the output to a file)?
Printable View
I have a VB6 program that needs info that I could find by running a command line command. Is there a way I could shell the command, then grab the output (other than writing the output to a file)?
Shell the program like this:
Then have the other program get the data like this:Code:'
'
Shell "path-to-program\program.exe data" '<-- space between .exe and the data
'
'
Code:Private Form_Load()
Dim InputData As String
InputData = Command()
If InputData <> "" Then
'
' Process the data
'
End If
End Sub
Ok, I think I need to clarify. First of all, I'm not looking to pass data from one executable to another. What I have is a command (command line command) that produces output. For example, if I type "date /t" at the command line, the date is outputted at the command line. How can I do this within a vb6 program and grab the output?
there are examples posted in code bank for doing this, using named pipe, but the code is quite complex, i have a simple example using scripting that also works,
are you sure you can not get the information using a windows function or api?
I would be very much willing to use an API. There seems to be an API called ReadConsoleOutput, but I can't find any good VB6 examples of how to use it. I see examples done in C++. Any help would be appreciated. I also found this...
http://www.vbforums.com/showthread.php?t=364219
But I can't seem to make the code work for me. Also, I have only one line of code to grab. In fact, the command only produces a one word output on the command line. I'm sure there is an easy way to grab it, but I can't figure out how.:(
i meant an api to get the value, instead of a commandline program or command, but as you have not specified what you are trying to return, it is hard to suggest a method
you can test this to see if it will work for you
vb Code:
Dim myobj As Object, strtxt As String Set myobj = CreateObject("wscript.shell") Set myobj = myobj.exec("ping www.google.com") 'your shell command Do With myobj With .StdOut If Not .AtEndOfStream Then strtxt = strtxt & .readall() End If End With End With DoEvents Loop While myobj.Status = "WshRunning" Set myobj = Nothing MsgBox strtxt ' ping results displayed in messagebox
Westconn1, that is awesome!:thumb: It works great! I did have to add "cmd /c" before listing my executable... like this:Quote:
Originally Posted by westconn1
Set myobj = myobj.exec("cmd /c c:\myDosProgram.exe")
Thank you so much for your help!
Westconn1, is there a way to hide the command window? If not, it's not a big deal, but if it's doable, please let me know.
Thanks!
dunno you could set your form to topmost or appactivte may be hide the dos box, immediately after myob.exec, never really tried