Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display command line output?

Status
Not open for further replies.

bitbrain

Programmer
Jun 10, 1999
159
US
I have a VB program that will be executed from the DOS/Command line (no windows/forms). It accepts an argument and performs a simple task.<br>
<br>
How do I display messages on the console? Seems like it ought to be easy but I can't figure out how. Any ideas will be appreciated.
 
Love to help you here...but to my knowledge(somewhat limited :)) does't do this. :(. <br>
<br>
Hey...you could output to a batch file...then execute the batch file? (use echo to out to screen...use a .pif to control the MS-dos screen) Might be worth a try! Thanks for the info in COBOL....hope this helps.
 
AS a very experienced batch programmer, I can tell you that positran's suggestion WILL WORK with QB4.5, but I am unsure of the output calls in VB...I have the CDs, but am waiting for my new hard drive that can handle VB sized progs. to be delivered.<br>
<br>
<br>
-Robherc<br>
robherc@netzero.net
 
You could also write it to a file in VB, and get hold of a utility to allow you to open a file and keep reading its input (ie like 'tail -f' in UNIX). I know that there are alot of x86 free versions of this utility kicking about.<br>
<br>
You would have to open two Command line windows for this, one to run the program, and the other to read the message file. I tend to do this alot on my Logging file, so I can interactively watch what is happening in the code, while users are running the Application. Bonus of this is it gives you a Log file of operation as well.<br>
<br>
Hope this helps.<br>

 
I may have missed something here....<br>
Why can't you use MsgBox to display the messages? Or are you trying to stay off the desktop?<br>
<br>
Ret = MsgBox("I don't understand.", vbAbortRetryIgnore)<br>
<br>

 
is there an VB alternative to the QB PRINT statement that simply returns output to the user's screen? Or is Microsoft just to stuck up to keep a good function around for us?<br>
<br>
<br>
-Robherc
 
Hmmm...<br>
<br>
Showing my age here, this worked in MSDOS 2.x and 3.x because it writes direct to the console device.<br>
<br>
Open the device "con:" (in the way you would open a file to write to it - or the device "lpt1:" if you were printing in DOS) and write to it.<br>
<br>
I can't beleive I remembered that.<br>
<br>
Mike<br>

 
like:<br>
OPEN "LPT1:" FOR OUTPUT AS #!<br>
PRINT #1, "message text here"<br>
??<br>
(i know, I know....QB4.5 code, but it *might* work with VB.<br>
<br>
<br>
-Robherc
 
Oops...THAT example would print it, but I think it well conveys my idea (substitute "CON:" for "LPT1:" and it should work right)<br>
<br>
<br>
-Robherc
 
Hmph...<br>
<br>
Doesn't work.<br>
<br>
So - the question is: "How do you write to an NT cmd.exe window from a VB program?"<br>
<br>
Interesting - I'll think some more.<br>
<br>
Mike<br>
---<br>
Mike_Lacey@Cargill.Com
 
Ok.... this one actually works. It's way out there but, after trying all the "reasonable" approaches, I decided to fall back on ol' favorite.<br>
For years, I have used a command.com replacement called 4DOS. It was (and might still be) available as shareware from JP Software.<br>
Right-click on 4DOS.COM and set the Cmd line properties to "C:\4dos.com /P:C:\4prompt.bat".<br>
Create the following C:\4prompt.bat:<br>
<br>
@ECHO OFF<br>
PROMPT=$%%@EXEC[C:\MESS]$_$P$G<br>
<br>
Create a Visual Basic form, set the visible property to false, add a timer control and set the interval property to the number of milliseconds you want to expire before updating your command line message. Add this code to the timer control:<br>
<br>
Private Sub Timer1_Timer()<br>
On Error Resume Next<br>
Header$ = "@ECHO OFF" + vbCrLf + "ECHO "<br>
' this is where you would set the text of your message.......<br>
Mess$ = "THIS IS A MESSAGE: " + Time$ + vbCrLf<br>
' ....the retrieval of the text for Mess$ would depend on the app<br>
Mess$ = Header$ + Mess$<br>
ff = FreeFile <br>
Open "C:\MESS.BAT" For Binary As #ff<br>
If Len(Mess$) &lt; LOF(ff) Then Mess$ = Mess$ + String$(LOF(ff) - Len(Mess$), " ")<br>
Put #ff, 1, Mess$<br>
Close #ff<br>
End Sub<br>
<br>
Run 4DOS and execute the VB app from the command prompt.<br>
The messages, followed by the standard $P$G prompt, will appear every time a command is executed or [ENTER] is pressed. For messages containing more than 22 CR+LF sequences you may want to insert some PAUSE statements in MESS.BAT.<br>
<br>
JP also had an NT command line interpreter called 4NT.<br>
<br>
Like I said... way out there. But it works. Hope I've helped.<br>

 
You can get a 21-day trial copy of 4DOS, 4NT or 4OS2 from I guess command.com and cmd.com replacements aren't directly related to Visual Basic... but I wouldn't want to do ANY kind of programming without them.<br>
I use 4DOS at work and at home (I spend about 60% of my day at the command prompt and ALT-TAB back to the desktop when I feel a need to click the mouse). This is addictive stuff!<br>
I guess executing commands with the keyboard restores the sense of control I felt before Windows hijacked my computer....
 
Thanks to all for your help. I picked-up some new pointers.<br>
<br>
In an effort to keep things simple; I modified the VB program to write messages to a log file. I wrote a bat/cmd script to execute the program then type the log file.<br>
<br>
Thanks again.
 
Jeez, bitbrain, I could've done THAT. I thought you were looking for the most complicated and improbable solution! Next time I'll suggest you call interrupt 2Eh with DS:SI pointing to "ECHO This works too!"<br>
Of course, it's awfully hard to do that in VB and it would probably ruffle some NT feathers....<br>
<br>
Glad you found a solution.<br>
<br>

 
The question is still: "How do you write to an NT cmd.exe window from a VB program?"<br>
<br>
Would be nice....<br>
<br>
Mike<br>
---<br>
Mike Lacey@Cargill.Com
 
Mike, you posted the challenge. There doesn't appear to be an easy way to do this with "straight" VB. Calls to User32 appear to be lacking here, too (unless I missed something that should've bitten my leg!).<br>
VB can't SendKeys a good string to a command/cmd window.<br>
Interrupt 2Eh, which I haven't tried since DOS 5.0, blows a window or EMM386 out of the water (maybe some of the old DOS hands remember interrupt 2Eh.... it allowed you to execute an external or internal command without loading an extra copy of the command processor).<br>
Mike, maybe you already know the answer to this one. If you don't... then let's define some ground rules.<br>
<br>
1) The function has to work without the help of third-party add-ons, TSR's of any kind, visible windows, msgboxes, additional copies of command.com/cmd.exe, NT trickery (let's make this work in Win9x, too), command processor replacements OR calls to the API. There....<br>
<br>
That's it... Just 1). Agreed???<br>
<br>
Bitbrain's original post stated that it ought to be easy.<br>
<br>
Regards, Alt255<br>
<br>

 
Sorry. My last post wasn't intended as a direct challenge. It REALLY ought to be EASY. Maybe VB hasn't reached the feature saturation required to make ordinary things EASY for users.<br>
If anyone has an EASY answer to this problem, please post it here. I will use it every day.<br>

 
Alt255 - Could we do the detailed discussion by email?<br>
<br>
Mike_Lacey@Cargill.Com<br>

 
I haven't tried this yet, but could you call the Win32 function wprintf()???<br>
<br>
The only catch might be that it has a variable-length argument list. Haven't done one of those yet. Maybe Dan Appleman's book covers it, but my copy is at home.<br>
<br>
Chip H.<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top