|
-
Nov 25th, 2008, 03:32 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Need to grab output from the command line
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)?
-
Nov 25th, 2008, 04:50 PM
#2
Re: Need to grab output from the command line
Shell the program like this:
Code:
'
'
Shell "path-to-program\program.exe data" '<-- space between .exe and the data
'
'
Then have the other program get the data like this:
Code:
Private Form_Load()
Dim InputData As String
InputData = Command()
If InputData <> "" Then
'
' Process the data
'
End If
End Sub
-
Nov 25th, 2008, 07:53 PM
#3
Thread Starter
Hyperactive Member
Re: Need to grab output from the command line
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?
-
Nov 25th, 2008, 08:13 PM
#4
Re: Need to grab output from the command line
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 do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 25th, 2008, 08:19 PM
#5
Re: Need to grab output from the command line
-
Nov 25th, 2008, 08:28 PM
#6
Thread Starter
Hyperactive Member
Re: Need to grab output from the command line
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.
-
Nov 25th, 2008, 08:47 PM
#7
Re: Need to grab output from the command line
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 26th, 2008, 06:07 AM
#8
Re: Need to grab output from the command line
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 26th, 2008, 08:18 PM
#9
Thread Starter
Hyperactive Member
Re: Need to grab output from the command line
 Originally Posted by westconn1
you can test this to see if it will work for you
Westconn1, that is awesome! It works great! I did have to add "cmd /c" before listing my executable... like this:
Set myobj = myobj.exec("cmd /c c:\myDosProgram.exe")
Thank you so much for your help!
-
Nov 26th, 2008, 08:24 PM
#10
Thread Starter
Hyperactive Member
Re: Need to grab output from the command line
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!
-
Nov 26th, 2008, 08:57 PM
#11
Re: Need to grab output from the command line
dunno you could set your form to topmost or appactivte may be hide the dos box, immediately after myob.exec, never really tried
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|