|
-
Jun 8th, 2001, 06:59 AM
#1
Thread Starter
Junior Member
get data from DOS exe
Hello,
Can anybody tell me how I could obtain in my VB app what is displayed on the command window by a command line exe.
The fact is that I am trying to make a GUI for a command line app for my little bro... and I actually need to display some infos in my app since he will not be able to find them out among the lot of lines printed by the dos tool.
I plan to to use shell() to run the DOS exe.
Thanks for your help
Black Rose of the Artist Clan
-
Jun 8th, 2001, 07:02 AM
#2
Here's an example:
VB Code:
Private Sub Form_Load()
Shell "command.com /c Dir /b c:\windows > c:\cListing.txt", 0
End Sub
-
Jun 8th, 2001, 07:03 AM
#3
Fanatic Member
you can dump the results of the commands into a file:
VB Code:
Shell("netstat > log.txt", vbNormalFocus)
and then read in the file in vb:
VB Code:
Dim Buffer As String
Dim Temp As String
Open "log.txt" For Input As #1
Do Until EOF(1)
Input #1, Temp
Buffer = Buffer & Temp
Loop
and then kill the file:
hope this helps
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Jun 8th, 2001, 07:08 AM
#4
You can redirect the output to a file and then parse that file for the information you need.
Unfortunatly you can't simply use the > character from Windows to redirect to file so the solution is to have your app create a BAT file and shell that.
Code:
Public Sub ShellIt(ByVal AppToShell As String, ByVal RedirectTo As String)
Dim hFile As Integer
Dim sBatFile As String
sBatFile = Environ("Temp")
sBatFile = sBatFile & IIf(Right$(sBatFile, 1) <> "\", "\tmpBat.Bat", "tmpBat.Bat")
hFile = FreeFile
Open sBatFile For Output As #hFile
Print #hFile, "@" & AppToShell & " >" & RedirectTo
Close #hFile
Shell sBatFile, vbHide
End Sub
You call the above procedure like this:
Code:
ShellIt "c:\TheDosApp.exe", "c:\Output.txt"
After that simply parse the Output.txt file and show whatever information you want from it.
Best regards
-
Jun 8th, 2001, 07:40 AM
#5
Thread Starter
Junior Member
Waouh !
3 answers in less than an hour !
that's that fast !
thank you very much !
Matthew Gates> can you explain me what is this ,0 at the end of
Shell "command.com /c Dir /b c:\windows > c:\cListing.txt", 0
I thought it was just shell "myapp.exe"
And, as Iam a newbie at DOS, could you explain me the details of the command line ?
Black Rose of the Artist Clan
-
Jun 8th, 2001, 09:26 AM
#6
Ok.
You've got a dos program called myapp.exe that displays lots of info when run.
To get that info you have to redirect the text to a file. This is done by running the program as "myapp.exe > c:\somefile.txt". This can be done using the Shell statement as:
Shell "c:\myapp.exe > c:\somefile.txt"
After this , read the file c:\somefile.txt into your program with some code like this :
dim strText as string
Open "c:\somefile.txt" for input as #1
strtext = input(1,lof(1))
close #1
That's it. You now have all the text displayed by the Dos program in a variable.
-
Jun 8th, 2001, 02:47 PM
#7
Re: Waouh !
Originally posted by ciler
3 answers in less than an hour !
that's that fast !
thank you very much !
Matthew Gates> can you explain me what is this ,0 at the end of
Shell "command.com /c Dir /b c:\windows > c:\cListing.txt", 0
I thought it was just shell "myapp.exe"
And, as Iam a newbie at DOS, could you explain me the details of the command line ?
The 0 is to hide the DOS window. It can be 0 or vbHide.
The Shell function can be used to launch COM and BAT files as well.
Command.com <-MS-DOS
/c <- Executes the specified command and returns.
Dir <-specifies files and folders in a directory
/b <-uses bare format (no heading or summary)
> <-Output to file
c:\cListing.txt <-file the information was written to
, 0 <-vbHide - hides the MS-DOS window, you can change this to 1 or vbNormalFocus if you wish to see the DOS Window.
-
Jun 8th, 2001, 03:12 PM
#8
Thread Starter
Junior Member
:( It don't works ...
I tried to use the > dos command, it creates a text file, but the file is empty
(either in dos mode or with VB and shell)
Here is my code :
c:\TestDir\normalize.exe -o test.wav jenina.wav > log.txt
(syntax for normalize is : normalize -o <file> input-file)
I can't figure what I did wrong ?
Thanks for any help
Black Rose of the Artist Clan
-
Jun 9th, 2001, 04:51 AM
#9
Does the program prompt you to enter any information when run normally ?
-
Jun 9th, 2001, 05:10 AM
#10
Thread Starter
Junior Member
wooops !
Yep, now it works !
And btw I know that it is useless trying to read the file while the process (here normalize) is still working...
Thank you for your help !
Black Rose of the Artist Clan
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
|